views:

62

answers:

2

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:
+1  A: 

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 gat a notification at a single point. Using UIViewController's methods bind you within these controllers, where you'd have to write/call shard 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
Max Seelemann
+1  A: 

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.

vfn