UINavigation,UiView,ModalView Controller之间的关系
2015-02-24 21:21
381 查看
如果当前是个VC,那么就太简单了,直接就可以push到下一个vc
AddShopViewController *controller = [[AddShopViewController alloc] init];
controller.view.backgroundColor = [UIColor whiteColor];// 设置背景色为白色,消除残影
[self.navigationController pushViewController:controller animated:YES];
有时候需要从modal view里pushviewcontroller,这当然是不行的,因为你没有NC,可以NSLog一下试试就知道了。
这时你要加某个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];
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];
相关文章推荐
- UIWindow,UINavigationController与UIViewController之间的关系
- iOS 导航栏控制器UINavigationController 、UINavigationBar、UINavigationItem 之间的关系(一)
- 如何让你的UINavigationController.rootViewController 占领这个屏幕?UINavigationController UIView fullScreen
- 透过Delegate ,看UIView与UIViewController之间的关系
- ios controller初始化,application,window,controller和view之间的关系
- 视图(view)、视图控制器(view controller)之间的数量关系
- presentModalViewController and UINavigationController
- UIWindow UIScreen UIViewController UIView之间的关系
- 如何让你的UINavigationController.rootViewController 占领这个屏幕?UINavigationController UIView fullScreen
- DAO,Service,Controller,View层之间的逻辑关系
- iOS 导航栏控制器UINavigationController 、UINavigationBar、UINavigationItem 之间的关系(二)
- 【转】UINavigationController 和 ModalViewController
- CodeIgniter web框架学习(1)-- view、controller之间的关系,及静态页面的加载实例
- iOS - 使用ZoomingViewController来放大UIView至全屏
- iPhone开发进阶(7)--- 利用ModalViewController切换View
- qt scene view 之间关系
- UINavigationController and viewWillAppear / viewDidAppear
- iPhone开发进阶(7)— 利用ModalViewController切换View
- iOS开发——Modal View Controller的不同呈现类型
- 【转】总结.NET MVC中Controller与View之间的数据传递