开发者

How to switch to another view

开发者 https://www.devze.com 2023-01-17 03:00 出处:网络
The following code should work, right? ViewController2 *childView = [[ViewController2 alloc] initWithNibName:@\"ViewController2\" bundle:nil];

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

精彩评论

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