开发者

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.开发者_StackOverflow The view just doesn't get switched. viewDidLoad does not even execute inside ViewController2.


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.


Use this:

[self presentModalViewController:viewControllerNameHere animated:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜