pushViewController和presentViewController的区别
2015-11-23 21:38
357 查看
pushViewController和presentViewController的区别
2014-4-15阅读3344 评论1
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];
}
//////////////////////
1、self.view addSubView:view 、self.window addSubView,需要注意的是,这个方法只是把页面加在当前页面。此时在用self.navigationControler.pushViewController和 pushViewController 是不行的。要想使用pushViewController和popViewController进行视图间的切换,就必须要求当前视图是个NavigationController。
2、就是使用self.navigationControler pushViewController和popViewController来进行视图切换的,pushViewController是进入到下一个视图,popViewController是返回到上一视图。
3、没有NavigationController导航栏的话,使用self.presentViewController和self.dismissModalViewController。具体是使用可以从文档中详细了解。
4、要想使用pushViewController和pushViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的。这里提供一个简单的方法让该视图或者根视图是NavigationController。自己定义个子类继承UINavigationController,然后将要展现的视图包装到这个子类中,这样就可以使这个视图是个NavigationController了。提供的这个方法有很好的好处,就是可以统一的控制各个视图的屏幕旋转。
2014-4-15阅读3344 评论1
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];
}
//////////////////////
1、self.view addSubView:view 、self.window addSubView,需要注意的是,这个方法只是把页面加在当前页面。此时在用self.navigationControler.pushViewController和 pushViewController 是不行的。要想使用pushViewController和popViewController进行视图间的切换,就必须要求当前视图是个NavigationController。
2、就是使用self.navigationControler pushViewController和popViewController来进行视图切换的,pushViewController是进入到下一个视图,popViewController是返回到上一视图。
3、没有NavigationController导航栏的话,使用self.presentViewController和self.dismissModalViewController。具体是使用可以从文档中详细了解。
4、要想使用pushViewController和pushViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的。这里提供一个简单的方法让该视图或者根视图是NavigationController。自己定义个子类继承UINavigationController,然后将要展现的视图包装到这个子类中,这样就可以使这个视图是个NavigationController了。提供的这个方法有很好的好处,就是可以统一的控制各个视图的屏幕旋转。
相关文章推荐
- linux 软中断和tasklet
- javascript_DOM 编程艺术学习笔记(八)
- 大二这一年的技术之旅
- PAT 1081. Rational Sum (20)
- Unity3D游戏引擎最详尽基础教程
- 我的IntellJ Idea学习笔记
- 矩阵转置的一般算法
- mac安装linux虚拟机
- android中Baseadapter的 getItem 和 getItemId 的作用和重写
- Swift学习笔记(三)
- UIViewController
- iOS应用版本更新(自动提醒用户更新代码)
- HashTable和HashMap的区别
- ViewStub的简单介绍
- Linux Bash 编程基础
- 1014. Waiting in Line (30)
- Hibernate整体理解
- 0-1背包问题
- AIDL简单使用
- Synchronized同步的考虑