2

Trying to get my head around protocols and delegates when extending it further into the UIKit framework's implementation.

From my understanding of this stackoverflow post a delegate method will usually have Did, Should & Will in it's name.

Based on this, I would assume that - (void)viewDidLoad; declared in UIViewController.h is a delegate method, but of what and from where?

I've looked at UIViewController's header file and it only adhere's to the NSCoding protocol which is a dead end. UIViewController's superclass UIResponder is also a dead end as far as I can see.

I've used viewDidLoad as an example here but this could apply to any of the Did, Should & Will methods in UIViewController.

Is this simply one of those cases that is an exception to the guidelines or am I missing something?

Community
  • 1
  • 1
craigmarch
  • 534
  • 3
  • 9
  • it's not a delegate method, it's just part of the UIViewController's class – Alex Coplan Aug 11 '11 at 09:52
  • That was my thinking and that the framework has kept the semantics Did, Should & Will more for reference to when the methods are invoked during the lifecycle. I'd imagine then that there are some hooks in UIViewController's implementation to the device's hardware that we just don't need to see. – craigmarch Aug 11 '11 at 10:36

1 Answers1

1

"did", "should", and "will" are words usually used to describe when a method is called, whether it is asking if it "should" do something", giving you a hook to run code before something "will" happen, or as a callback when something "did" happen. these words are usually used in delegate and callback methods.

viewDidLoad is called when your .nib file has been loaded into memory, and your IBOutlets have been instantiated and hooked up, and are ready for configuration. you don't need to worry about calling it yourself if you intend to subclass UIViewController, if that's what you're wondering.

Daniel Byon
  • 198
  • 6
  • I wasn't looking to call viewDidLoad, more trying to understand why there are delegate methods with Did, Should & Will in their name that you would declare via a protocol declaration in @interface, and then there are these other methods (such as `viewDidLoad`) that also contain Did, Should & Will that you simply inherit from a superclass. However, after some more research, I think was mistaken in my initial belief that any event type method had to come from a protocol, when it is simply a way for 2 non inherited classes to communicate. – craigmarch Aug 11 '11 at 17:28