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

Advertisements

Editable UITableViewController

UITableView

A common use case in iOS is creating a form or an editable list of records directly inside a UITableView. We could send the user to a separate “detail” view controller for editing, but that complicates and slows down the user experience. In this post, I’ll show you how to create your own subclass of UITableViewController that can support any number of UITextFields inside your table cells and use them to update any backing data source. This code can then be reused in any project that needs an editable table view!

Continue reading