UINavigationController的setViewControllers方法
来源:互联网 发布:迷奇化妆品怎么样知乎 编辑:程序博客网 时间:2024/06/04 20:27
在iOS开发中,UINavigationController是很常用的Controller,对它的一般操作就像操作一个栈,push和pop。但也经常会遇到pop和push无法优雅的完成的操作,比如退回到中间的某个VC上,或者在第一个VC之前添加一个VC等,更甚者要重新构造整个VC的顺序,这时候setViewControllers方法就排上用场了,它使对VC栈的操作不再局限于push和pop,而是构造整个VC栈并应用到当前的UINavigationController中,这个方法支持iOS3.0+,放心使用。
例如:当前我处于视图控制器A ,我想打开一个视图控制器C,但出于某个目的(预加载)打开控制器B,但又想保留之前的控制器栈
NSMutableArray * viewControllers = [self.navigationController.viewControllers mutableCopy];//获取到当前导航控制器栈中所有vcUIViewController *vcB=[UIViewController new];UIViewController *vcC=[UIViewController new];[viewControllers addObjectsFromArray:@[vcB,vcC]];[self.navigationController setViewControllers:viewControllers animated:YES];// [viewControllers relase] // if non-arc
执行后,控制器跳转至C,在C中执行
[self.navigationController popViewControllerAnimated:NO];
你会发现是回到B,而不是A
说明
下面这段摘自Api文档
You can use this method to update or replace the current view controller stack without pushing or popping each controller explicitly. In addition, this method lets you update the set of controllers without animating the changes, which might be appropriate at launch time when you want to return the navigation controller to a previous state.If animations are enabled, this method decides which type of transition to perform based on whether the last item in the items array is already in the navigation stack. .If the view controller is currently in the stack, but is not the topmost item, this method uses a pop transition; .if it is the topmost item, no transition is performed. .If the view controller is not on the stack, this method uses a push transition. Only one transition is performed, but when that transition finishes, the entire contents of the stack are replaced with the new view controllers. For example, if controllers A, B, and C are on the stack and you set controllers D, A, and B, this method uses a pop transition and the resulting stack contains the controllers D, A, and B. <br /> Have fun! <br /> <br />
0 0
- UINavigationController的setViewControllers方法
- UINavigationController的setViewControllers方法----->>push一组界面
- ios7下setViewControllers的问题
- 页面的跳转技巧--setViewControllers
- 页面的跳转技巧--setViewControllers
- UINavigationController的代理方法
- UINavigationController的隐藏方法
- 使用setViewControllers实现一些不同寻常的跳转
- 改变UINavigationcontroller的方法 记录下来
- UINavigationController的 initWithNavigationBarClass:toolbarClass: 创建方法使用
- UINavigationController属性与方法
- UINavigationController 常用方法
- 在UINavigationController下的-(void)viewWillAppear:方法失效的解决办法
- 在没有UINavigationController的情况下,显示状态栏的方法
- 给UIViewController的UINavigationController属性赋值的方法
- 解决UINavigationController+UITabbar跳转页面隐藏tabbar的一种方法
- UINavigationController(导航控制器)及跳转页面的方法
- UINavigationController返回前面界面的几种方法
- Eclipse关联JDK源码
- DirectShow媒体文件回放总结
- Tarjan算法模板
- 正则表达式常见表
- ASP.NET-GridView分页排序显示
- UINavigationController的setViewControllers方法
- scala 执行 hive,hadoop,mysql等命令
- lua标准库加载过程分析
- void Uart_Printf(char *fmt,...)
- Android常用工具类
- XEP100移植FATFS文件系统
- Xcode中使用sqlite3访问数据库
- 值类型 引用类型 ref out
- freemarker 模板引擎