I believe that UIView objects can delegate control to views in iOS programming. However, I thought this was already handled by an IBAction associated with an IBOutlet corresponding to the UIView.
In that case, what does it mean to drag a blue line (while pressing Ctrl) from the delegate circle of the UIView in my xib to File Owner?
Isn’t the UIView already delegating to my view controller via an IBAction? The code seems to work if I don’t specify anything for my UIView‘s delegate.
It looks like you’re confusing the idea of the Target-Action Mechanism with delegation. While you could in a way think of target-action as involving “delegation”, it would only be in the most general sense of the word in that it’s the target (generally a controller) that handles and implements the action (the message). However, a Cocoa programmer would probably refrain from explaining the target-action mechanism by using that particular word – delegation – as it would be too easy to confuse it with actual Delegation.
When you “wire up” buttons and controls in the nib file to call
IBActionmethods in your controller object, that’s just the target-action mechanism at work. As you saw, the code works even if you “don’t specify anything for myUIViewdelegate”, since target-action doesn’t involve delegation (in the Cocoa-sense of the word).Delegation is generally used as an easier alternative to using subclassing to implement the desired behavior. For example, instead of having to create your own custom subclass of
UITableViewin order to have it know what data you want it to display, you can simply use the plainUITableViewclass, set itsdelegateto a controller class, and have the controller class implement the required/desired designated delegate methods. Using subclassing to accomplish that could potentially get complicated, since when you subclass, you need to have a full understanding of the inheritance chain and how all of the superclasses work.