pushViewController/presentModalViewController/addSubView区别及使用方法
2015-09-01 17:07
169 查看
1. 用UINavigationController的时候用pushViewController:animated
----返回之前的视图[[self navigationController]
popViewControllerAnimated:YES];
---ps:push以后会在navigation的left
bar自动添加back按钮,它的响应方法就是返回。所以一般不需要写返回方法,点back按钮即可。
2. 其他时候用presentModalViewController:animated
[self presentModalViewController:controller animated:YES];//YES有动画效果
-----返回之前的视图 [self dismissModalViewControllerAnimated:YES];
3. 切换视图一般用不到addSubview
UINavigationController是导航控制器,如果pushViewController的话,会跳转到下一个ViewController,点返回会回到现在这个ViewController;
如果是addSubview的话,其实还是对当前的ViewController操作,只是在当前视图上面又“盖”住了一层视图,其实原来的画面在下面呢,看不到而已。(当然,也可以用insertSubView atIndex那个方法设置放置的层次)。
另加一个
使用presentModalViewControllerAnimated方法从A->B->C,若想在C中直接返回A,则可这样实现:
C中返回事件:
void back
{
[self dismissModalViewControllerAnimated:NO];//注意一定是NO!!
[[NSNotificationCenter defaultCenter]postNotificationName:@"backback" object:nil];
}
然后在B中,
//在viewdidload中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(back) name:@"backback" object:nil];
-(void)back
{
[self dismissModalViewControllerAnimated:YES];
}
----返回之前的视图[[self navigationController]
popViewControllerAnimated:YES];
---ps:push以后会在navigation的left
bar自动添加back按钮,它的响应方法就是返回。所以一般不需要写返回方法,点back按钮即可。
2. 其他时候用presentModalViewController:animated
[self presentModalViewController:controller animated:YES];//YES有动画效果
-----返回之前的视图 [self dismissModalViewControllerAnimated:YES];
3. 切换视图一般用不到addSubview
UINavigationController是导航控制器,如果pushViewController的话,会跳转到下一个ViewController,点返回会回到现在这个ViewController;
如果是addSubview的话,其实还是对当前的ViewController操作,只是在当前视图上面又“盖”住了一层视图,其实原来的画面在下面呢,看不到而已。(当然,也可以用insertSubView atIndex那个方法设置放置的层次)。
另加一个
使用presentModalViewControllerAnimated方法从A->B->C,若想在C中直接返回A,则可这样实现:
C中返回事件:
void back
{
[self dismissModalViewControllerAnimated:NO];//注意一定是NO!!
[[NSNotificationCenter defaultCenter]postNotificationName:@"backback" object:nil];
}
然后在B中,
//在viewdidload中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(back) name:@"backback" object:nil];
-(void)back
{
[self dismissModalViewControllerAnimated:YES];
}
相关文章推荐
- UVA 6625(状态压缩dp)
- C++11(std::thread)
- iOS开发之指定UIView的某几个角为圆角
- 关于MySQL数据被删除后空间重用的问题实验
- C++ 虚函数
- UIActivityViewController 自定义选项
- jquery 的ajax请求示例和注意事项
- UVA_11021 Tribles(递推)
- 编写更好的jQuery代码的建议
- Android系统中SystemServer进程中初始化的系统service
- JS设计模式——观察者模式
- Echarts异步模块定义(AMD规范)——require.js
- ArcGIS教程:流向
- R_Split-Apply-combine
- android沉浸式状态栏的实现
- android沉浸式状态栏的实现
- java中的注解
- 设计一种算法,产生一个不在某文件中的整数
- android沉浸式状态栏的实现
- WEB程序需要打印格式页面时解决方案汇总 .