美文网首页iOS知识点
如何判断UIViewController是使用pop,dism

如何判断UIViewController是使用pop,dism

作者: VincentHK | 来源:发表于2017-05-03 19:27 被阅读85次

    当我们自定义继承UIViewController视图控制器的基类视图控制器时,会新增返回到上级的视图控制器方法,于是就要区分,返回时使用 pop 的方法,还是使用dismiss 的方法了。

    方法1

    [html] view plain copy 在CODE上查看代码片派生到我的代码片

    - (void)backPreviousController

    {

    if (self.presentingViewController)

    {

    [self dismissViewControllerAnimated:YES completion:nil];

    }

    else

    {

    [self.navigationController popViewControllerAnimated:YES];

    }

    }

    方法2

    [objc] view plain copy 在CODE上查看代码片派生到我的代码片

    - (void)backPreviousController

    {

    if (self.navigationController.topViewController == self)

    {

    [self.navigationController popViewControllerAnimated:YES];

    }

    else

    {

    [self dismissViewControllerAnimated:YES completion:nil];

    }

    }

    方法3

    [objc] view plain copy 在CODE上查看代码片派生到我的代码片

    - (void)backPreviousController

    {

    if ([self.navigationController.viewControllers.firstObject isEqual:self])

    {

    [self dismissViewControllerAnimated:YES completion:nil];

    }

    else

    {

    [self.navigationController popViewControllerAnimated:YES];

    }

    }

    [html] view plain copy 在CODE上查看代码片派生到我的代码片

    - (void)backPreviousController

    {

    if ([self.navigationController.viewControllers indexOfObject:self] == 0)

    {

    [self dismissViewControllerAnimated:YES completion:nil];

    }

    else

    {

    [self.navigationController popViewControllerAnimated:YES];

    }

    }

    相关文章

      网友评论

        本文标题: 如何判断UIViewController是使用pop,dism

        本文链接:https://www.haomeiwen.com/subject/zdjltxtx.html