iPhone Development 101

iPhone 101

Code Tips

Resources

Links

Follow

Mailing ListTwitter

More

iPhone Development 101: User Interface: UINavigationController:
Pushing and popping views off a UINavigationController stack

A navigation controller manages views by pushing/popping them on/off the controller's view stack. When you push an item, the current view slides off screen to the left, and the new view slides over from the right.

If you're using storyboards, the storyboard segues manage the view transitions for you, and you don't need this code.

If you're not using storyboards, and instead have separate Interface Builder nib (xib) files for each of your views, you'll have to add code to push views manually.

To push a controller:
    SecondViewController *viewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
    [[self navigationController] pushViewController:viewController animated: YES];
    [viewController release];

When popping an item, the current view slides right and is deallocated:

    [[self navigationController] popViewControllerAnimated:YES];

The slide-over effect only happens if the animated arguments are YES.


TopHome