UINavigationController with Push and Pop Blocks

 

jumbo_push_pops_18_pack-large

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

Why Static Code is Bad

static

Most object-oriented developers are familiar with static methods and classes. They are present in most programming languages including C# and Objective-C (where they are known as class methods). Here are some common cases in which they are used: Continue reading