UINavigationController with Push and Pop Blocks



When creating view controllers programmatically, one of the options is to use a UINavigationController as a container. This allows you to push and pop view controllers on the navigation stack. However, here are some common developer complaints:

  1. You can’t easily capture the ‘pop’ event. That includes ‘back’ button presses. A common solution is to rely on your top view controller’s viewWillDisappear event. However, you still need logic to check whether this event was fired in response to a new controller being pushed instead of it itself being popped.
  2. Showing the navigation bar and toolbar is tricky. This can result in some unexpected animation effects. If setNavigationBarHidden:NO or setToolbarHidden:NO is called too early, the bars will appear before the the controller starts pushing. A solution is to set this in the pushed view controllers’ viewWillAppear event.

Continue reading