Search code examples
iphoneobjective-ciospushviewcontroller

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.


Solution

  • 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.