若是當前是個VC,那麼就太簡單了,直接就能夠push到下一個vc
AddShopViewController *controller = [[AddShopViewController alloc] init];
controller.view.backgroundColor = [UIColor whiteColor];// 設置背景色爲白色,消除殘影
[self.navigationController pushViewController:controller animated:YES];
有時候須要從modal view裏pushviewcontroller,這固然是不行的,由於你沒有NC,能夠NSLog一下試試就知道了。
NSLog(@"ViewControllers before pushing: %@", self.navigationController.viewControllers);
這時你要加某個viewController的view在你的self.view上,你必須作的是:[self addChildViewController:xxx];或者addSubview。由於沒有nav,若是想用nav來控制vc,通常是先有nav,而後把vc加入nav中,若是自己就是個vc那麼直接
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:self];
[self presentViewController:navController animated:YES completion:nil];
這樣你的modal就有一個nv,那麼你就能夠在這個modal裏邊用[self.navigationController pushViewController:controller animated:YES];
完整的一個寫法是這樣的,Storyboard表述的很清楚
MyViewController *myViewController = [MyViewController alloc] init];
UINavigationController *navController = [UINavigationController alloc] initWithRootViewController:myViewController];
// Presuming a view controller is asking for the modal transition in the first place.
[self presentViewController:navController animated:YES completion:nil];