present和push的区别
2015-11-20 10:15
357 查看
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];
}
相关文章推荐
- 获取ResultSet集合查询出的字段名称
- Linux 随手记1
- 单播和广播的区别
- Oracle select * and rownum
- Excel将Unix时间戳转换为日期
- CenOS Linux安装nginx
- Java发送邮件
- SVN Web服务器实时更新配置
- android中如何执行java命令
- MySQL审计功能
- vsftpd安装、多用户配置
- Android SharedPreferences一般的读写 的用法。
- 对克隆实体的类型转换
- java反射机制setter方法使用
- Java常用的7大排序算法汇总
- poj3177Redundant Paths【构造双连通分量:并查集缩点 模板】
- 4.1 SQLite 存储类型
- JavaScript高级程序设计(第3版)中文在线阅读
- Activity间的跳转
- 监理工程师岁月--三流大学生的困惑