何时使用 IBOutlet?
我对 IBOutlet 有点困惑。当变量在笔尖中更改时,我应该使用 IBOutlet 吗?
I'm a little confused about the IBOutlet.Is it right I should use the IBOutlet when the variable will be changed in the nib?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您想要对在 Interface Builder 中创建的视图执行某些操作时,可以使用 IBOutlet。例如,您在 Interface Builder 中放置了一个按钮,并且想要从代码中更改其标题/标签,将 IBOutlet(名称如 button1)附加到该按钮。然后从您的代码中,您可以调用 [button1 dosomething]。如果没有 IBOutlet,您实际上无法对在 Interface Builder 中创建的视图执行某些操作。简短的回答是肯定的,每当您想使用 Interface Builder 中创建的视图执行某些操作时,请始终使用 IBOutlet。
IBOutlet is used when you want to do something with a View you created in Interface Builder. For example, you put a button in Interface Builder and you want to change it's caption/label from your code, attach IBOutlet (with a name such as button1) to that button. Then from your code, you can call [button1 dosomething]. Without having IBOutlet, you have virtually no way to do some action to a View you created in Interface Builder. Short answer is yes, always use IBOutlet whenever you want to do something with a View created in Interface Builder.
当您需要访问对象的属性时,请使用 IBOutlet。如果您需要 UITextField 的文本或想要在代码中操作它,您可以 IBOutlet 文本字段。
但是,如果您有一个 UIButton,您不需要访问其属性,则无需 IBOutlet 它。您只需将 IBAction 连接到它即可。
(并不是说 UIButtons 不应该是 IBOutlet'ed,当然在某些情况下应该是 IBOutlet,而 UITextFields 不应该是)
Use IBOutlet when you need to access an object's properties. If you need the text of a UITextField or want to manipulate it in your code, you IBOutlet the text field.
However, if you have, say, a UIButton where you don't need to access its properties, you don't IBOutlet it. You just connect an IBAction to it.
(Not to say that UIButtons shouldn't be IBOutlet'ed, there certainly are cases where it should be, and where UITextFields shouldn't be)
我是IOS新手。我的理解是你需要一个标识符(你分配给你的按钮)来实际操作按钮事件。
示例:
代码:
@property(nonatomic,strong) IBOutlet UIButton *bttn;
I am new to IOS. What i understand is you need an identifier (which you assign to your button) for actually manipulating with button event.
Example :
Code:
@property(nonatomic,strong) IBOutlet UIButton *bttn;