UINavigationController Archives

How to hide navigation elements with swishy animations

You can hide (and show) navigation bars and toolbars from your UINavigationController with extremely funky animations, much like we see in the Photos app on iOS. In the app, when you single-tap the screen, both top and bottom toolbars disappear. Here’s how we do that: Provided you have your view controller embedded in a UINavigationController, […]

How to create a UIBarButtonItem in code and make it call a method

Some things are really easy to do via a Storyboard – but when you want to create the same thing in code I frequently forget how to do it. Turns out it’s equally simple: this example assumes you have a View Controller which is embedded in a Navigation Controller (so it already has a UINavigationBar […]

How to pass data from the App Delegate to your Top View Controller

If the App Delegate has something that your top view controller needs then you simply pass it the required object via a property set on the top view controller. This is easy when your top view controller is also the root view controller. However, when you embed your top view controller in a Navigation Controller, […]

How to pop a UINavigationController in code

In UINavigationController speak, we “push” new controllers onto the stack (go forward), and we “pop” them off the stack (go back). The navigation controller handles all this for us. If you want to go back exactly one view controller, here’s how you can do it programmatically: // pop back to previous controller NSArray *myControllers = […]

How to change the back button text on a UINavigationController

In Your Storyboard I didn’t know the storyboard could do this, but it can: Select the Navigation Bar in question, then check the Attributes Inspector: In Code To set the title in code, you need to address the self.navigationItem.backBarButton property of your view controller and pass it a new UIBarButtonItem. Here’s one way of doing […]