使用presentViewController跳转到上上个页面,实现多层跳转的两种方法。

来源:互联网 发布:升腾资讯java笔试 编辑:程序博客网 时间:2024/04/29 01:36
第一种方法
简单容易实现。
[self.presentingViewController.presentingViewController.presentingViewControllerdismissViewControllerAnimated:NOcompletion:nil]; 一定要是no才行。
第2种方法:
转自http://blog.csdn.net/xiaofansong/article/details/8011557
pushViewController/presentModalViewController/addSubView区别及使用方法 - 一件飘雪 - 博客频道 - CSDN.NET
使用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. }
    8. 第二种方法  [self.presentingViewController.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil]; 一定要是no才行。
0 0