cannyboy
cannyboy

Reputation: 24406

Why does this pushViewController not work?

I have a UIViewController class, which has a button which triggers this:

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

Why does the push do nothing? If it matters, the UIViewController is within a UITabBarController.

Upvotes: 4

Views: 4208

Answers (2)

Jonah
Jonah

Reputation: 17958

Because self.navigationController is nil? If you didn't create a UINavigationController to manage the contents of the current tab of your UITabBarController then you have nothing to push a new view controller onto.

Upvotes: 1

PengOne
PengOne

Reputation: 48398

My best guess for this in general is that you haven't yet created a UINavigationController. You need to create a UINavigationController first, then you can push onto the stack.

You can check for this by using the navigationController property to see whether the current viewController (self) is currently in a UINavigationController's hierarchy; if not , the navigationController property returns nil.

Upvotes: 5

Related Questions