[addChildViewController]View Controller中可以添加多个sub view,在需要的时候显示出来;
来源:互联网 发布:模拟退火算法 编辑:程序博客网 时间:2024/05/21 09:49
View Controller中可以添加多个sub view,在需要的时候显示出来;
可以通过viewController(parent)中可以添加多个child viewController;来控制页面中的sub view,降低代码耦合度;
通过切换,可以显示不同的view;,替代之前的addSubView的管理
//在parent view controller 中添加 child view controller//在parent view controller 中添加 child view controller FirstViewController *firstViewController=[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; [self addChildViewController:firstViewController]; SecondViewController *secondViewController=[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; [self addChildViewController:secondViewController]; ThirdViewController *thirdViewController=[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil]; [self addChildViewController:thirdViewController]; [self.view addSubview:thirdViewController.view]; // addChildViewController回调用[child willMoveToParentViewController:self] , // 但是不会调用didMoveToParentViewController,所以需要显示调用 [thirdViewController didMoveToParentViewController:self]; currentViewController=thirdViewController; //切换child view controller [self transitionFromViewController:currentViewController toViewController:firstViewController duration:4 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{ } completion:^(BOOL finished) { //...... }]; currentViewController=firstViewController; //移除child view controller // removeFromParentViewController在移除child前不会调用[self willMoveToParentViewController:nil] ,所以需要显示调用 [currentViewController willMoveToParentViewController:nil]; [currentViewController removeFromSuperview]; [currentViewController removeFromParentViewController];
博客原文地址
0 0
- [addChildViewController]View Controller中可以添加多个sub view,在需要的时候显示出来;
- View Controller容器(有助于理解addChildViewController)
- ViewSwitcher类解析,可以用来在两个View中切换显示,并添加切换动画
- 在一个Activity中使用多个View (可以借鉴的一种思路)
- 在UIView中添加多个大小一样的框框 (小View)
- ParentViewController中添加多个SubViewController的View
- 如何在Joomla的controller中关联Model和View
- 如何在controller中获得view实例
- Yii 在view中包含多个view
- 使用setContentView可以在Activity中动态切换显示的View
- 在View窗口中添加显示FTGL字体
- Android自定义可以在文字上方显示备注的View
- viewpager一屏显示多个view 并且可以预览下一个view
- 显示第一个view, 延迟三秒再显示第二个view,使用java的定时器timer实现 需要启动两个activity
- 为什么我在table view cell中添加的按钮不显示
- View转图片,View可以是显示在屏幕的也可在后台
- 在UIViewController的view上添加子视图不显示
- 添加 自定义的view,并显示在最前端
- 如何在windows下安装cygwin
- Windchill学习之WTObject主内容打包下载
- ZOJ1002 Fire Net(二分图匹配)
- ASP.NET常见对象之Request与Response
- 五种不同的 URL 参数解析方法的性能比较
- [addChildViewController]View Controller中可以添加多个sub view,在需要的时候显示出来;
- Color Me Less(POJ1046
- 1218THE DRUNK JAILER
- php远程抓取函数curl(),file_get_contents
- springmvc 使用ajax报406错误
- Executor接口
- C#中结构类型和类类型
- Denial Of Service(拒绝服务攻击)学习笔记(一)
- 在Python中处理XML的教程