node ninja
node ninja

Reputation: 32986

How to switch to another view

The following code should work, right?

ViewController2 *childView = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
 [self.navigationController pushViewController:childView animated:YES];
 [childView release];

It doesn't do anything though. There are no error messages. The view just doesn't get switched. viewDidLoad does not even execute inside ViewController2.

Upvotes: 2

Views: 191

Answers (2)

Daniel G. Wilson
Daniel G. Wilson

Reputation: 15055

Use this:

[self presentModalViewController:viewControllerNameHere animated:YES];

Upvotes: 0

Shaggy Frog
Shaggy Frog

Reputation: 27591

That code won't do anything if the view controller presenting it doesn't have a navigation controller, i.e. it isn't in a navigation controller stack. In that case, you'll be calling a method (pushViewController:animated:) on a nil object (self.navigationController) which does nothing. Thus, you can only use this this method if the "parent" view controller is in a UINavigationController stack.

Upvotes: 1

Related Questions