[apple]UI和class的连接

本文介绍如何在Xcode中通过Interface Builder创建对象实例,并建立不同对象间的连接,使得一个对象能向另一个对象发送消息。具体步骤包括在xib文件中实例化类、从按钮拖拽连线到目标对象,最终实现按钮点击时调用特定方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 An object has no way of sending a message to another object if it doesn't have a reference to the other object. 

 

We have now instantiated our MFAExampleClass class in Xcode into an object in our xib file. This will allow our code and our interface to communicate.

object instances themselves don't contain the code to perform the action, but the classes do.

 

To create the connections, press the Control key on you keyboard and use the mouse to drag from the "Set to 5"" button to the MFAExampleClass instance in the MainMenu.xib window (don't do it the other way around!). 

 

Now the button holds a reference to our MFAExampleClass object, and will send it the setTo5:message whenever it is pressed.

 

Generate Code: IB画好界面后,可以用xcode自动生成代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值