I'm having issues understanding the concept of outlets how the iPhone deals with events. Help! Delegates confuse me too. Would someone care to explain, please?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
A delegate is a object that another object can forward messages to. In other words, it's like when your mom told you to clean your room and you pawned it off on your little brother. Your little bro knows how to do the job (since you were too lazy to ever learn) and so he does it for you.
Outlets (in Interface Builder) are member variables in a class where objects in the designer are assigned when they are loaded at runtime. The
IBOutlet
macro (which is an empty#define
) signals Interface Builder to recognise it as an outlet to show in the designer.For example, if I drag out a button, then connect it to the
aButton
outlet (defined in my interface .h file), the loading of the NIB file at runtime will assignaButton
the pointer to thatUIButton
instantiated by the NIB.Then in the implementation:
This eliminates the need to write code to instantiate and assign the GUI objects at runtime.
As for Delegates, they are event receiving objects used by another object (usually a generalised API class such as a table view). There's nothing inherently special about them. It's more of a design pattern. The delegate class may define several of the expected messages such as:
...and the API object calls this message on the delegate when it wants to notify it of the event. For example:
And the delegate defines the message:
Such use might be: