首页 > 其他 > 详细

pushViewController

时间:2015-06-06 17:59:56      阅读:182      评论:0      收藏:0      [点我收藏+]
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中,

    1. //在viewdidload中:  
    2. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(back) name:@"backback" object:nil];  
    3.   
    4. -(void)back  
    5. {  
    6.      [self dismissModalViewControllerAnimated:YES];  
    7. }  

pushViewController

原文:http://www.cnblogs.com/zhgz/p/4556812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!