Try the search, it's linked to some great forums

Thursday, October 22, 2015

Pushing & Popping View Controllers

Pushing (adding to the stack) and Popping (removing from the stack) is a key technique for displaying your views on an iOS app.  Doing this incorrectly can create huge memory leaks & crashes.  Doing it properly can lead to beautiful transitions and navigation thru your app.

Here's some reference articles;
Back to Basics - View Controllers


Here is a code sample demonstrating how to push a view controller on to the navigation stack.

// Initialize MyViewController object
MyViewController *controller = [[MyViewController alloc] 
     initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
// Pushes MyViewController object on the navigation stack
[self.navigationController pushViewController:controller animated:YES];
[controller release];
 
In this example, we instantiate a new UIViewController subclass called MyViewController and push it on to the view controller stack. One very important detail to point out is, you must do this from inside of a view controller that is contained inside of a navigation controller, otherwise the “self.navigationController” property will be nil. navigationController is a property of every UIViewController subclass that gets set whenever it has been inserted into a UINavigationController.
Another thing to note is, we release the controller after pushing it on to the stack (prior to iOS5 with ARC). This is because the navigation controller will retain your view controller therefore preventing it from being released from memory.

The following code will pop the view controller off of the view stack with an animation.
[self.navigationController popViewControllerAnimated:YES];