iOS 界面跳转问题小节

iOS界面跳转详解

在iOS界面跳转中,有两种方法:

第一种是    presentViewController,返回方式为[self dissmissModelViewControllerAnimated:YES];

第二种是用self.navigationController pushViewController,返回方式为[self.navigationController popViewControllerAnimated:YES];


延伸用法:

1.如果用present的方法从a界面到b界面再到c界面,而且再从c界面返回到a界面

需要在c界面中写一个返回方法

- (void)back {

  • [self dismissModalViewControllerAnimated:NO];  
  •       [[NSNotificationCenter  defaultCenter]postNotificationName:@"comeBack" object:nil]; //发一个通知

    }


    再在b界面中写以下代码

    在viewDidLoad中写一个通知接收b界面发出的通知

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(back) name:@"comeBack" object:nil];  

    然后在b界面中实现back方法
    - (void)back 
     [self dismissModalViewControllerAnimated:YES];  
    }


    另:也可以自定义一个dismissToRootViewController

    -(void)dismissToRootViewController

    {

        UIViewController *vc = self;

        while (vc.presentingViewController) {

            vc = vc.presentingViewController;

        }

        [vc dismissViewControllerAnimated:YES completion:nil];

    }



    解释两个属性:

    presentingViewController和presentedViewController

    A----(present)-----B----(present)-----C

    那么A就是B的presentingViewController.

    C就是B的presentedViewController.

    另外,self调用dismiss方法会的时候会判断self.presentedViewController是否存在,如果存在,就只会将self.presentedViewController给dismiss掉,自己不会dismiss掉。所以我们一直遍历到最底层的控制器,然后调用dismiss方法,就会将所有的presentedViewController给dismiss掉。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值