Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When/why/how to use the UINavigationControllerDelegate Protocol Instance Methods?

When/why/how would you use these methods?

- navigationController:willShowViewController:animated:
– navigationController:didShowViewController:animated:

Can't you just use these UIViewController Instance Methods instead?

– viewWillAppear:
– viewDidAppear:
– viewWillDisappear:
– viewDidDisappear:
like image 307
ma11hew28 Avatar asked Aug 30 '10 01:08

ma11hew28


2 Answers

You'd use the first ones if you want to be informed about these events outside the visible view controllers. The delegates allow you to get a notification at a single point. Using UIViewController's methods bind you within these controllers, where you'd have to write/call same code multiple times to achieve the same.

Generally you'd divide tasks into these two groups:

  • Things that happen across all view controllers: use the delegates
  • Things happening within a single view controller: use the instance methods
like image 184
Max Seelemann Avatar answered Sep 29 '22 23:09

Max Seelemann


The UINavigationControllerDelegate protocol defines methods a navigation controller delegate can implement to change the behavior when view controllers are pushed and popped from the stack of a navigation controller.

These method are important when you need to perform some actions that would not be on the scope of your view controller. the delegate it's supposed to be a object predecessor of your view controller on the hierarchy and that would be interested in perform some actions without the knowing of each view controller that is pushed or popped, these actions are not necessarily related with that view controller specifically, but they can be methods called on other objects.

like image 20
vfn Avatar answered Sep 29 '22 22:09

vfn