如果当前是个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];
UINavigation,UiView,ModalView Controller之间的关系

相关文章:

  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-02-17
  • 2021-06-09
  • 2021-08-29
猜你喜欢
  • 2021-09-10
  • 2022-01-25
  • 2021-08-26
  • 2021-12-12
  • 2021-10-21
  • 2021-10-01
相关资源
相似解决方案