IBOutlet and IBAction

2019-01-01 02:59发布

What is the purpose of using IBAction and IBOutlet in Objective-C coding for the iPhone, does it make any difference if I don't use them?

8条回答
还给你的自由
2楼-- · 2019-01-01 04:02

An Outlet is a link from code to UI. If you want to show or hide an UI element, if you want to get the text of a textfield or enable or disable an element (or a hundred other things) you have to define an outlet of that object in the sources and link that outlet through the “interface object” to the UI element. After that you can use the outlet just like any other variable in your coding.

IBAction – a special method triggered by user-interface objects. Interface Builder recognizes them.

@interface Controller
{
  IBOutlet id textField; // links to TextField UI object
}

- (IBAction)doAction:(id)sender; // e.g. called when button pushed

For further information please refer Apple Docs

查看更多
萌妹纸的霸气范
3楼-- · 2019-01-01 04:02

IBAction and IBOutlets are used to hook up your interface made in Interface Builder with your controller. If you wouldn't use Interface Builder and build your interface completely in code, you could make a program without using them. But in reality most of us use Interface Builder, once you want to get some interactivity going in your interface, you will have to use IBActions and IBoutlets.

查看更多
登录 后发表回答