iOS present返回根视图解决方案

查了网上很多例子都不能解决我的问题,网上一堆辣鸡,然后查了一下资料和谭哥哥一起解决了问题。

去百度云盘看效果:

链接: https://pan.baidu.com/s/1Suyloq5g_2RL7HXNtvI0og 提取码: r3k9 复制这段内容后打开百度网盘手机App,操作更方便哦

问题:

A present B 之后,B 再 present  C或者D 的时候,B就会被dismiss掉。

解决方案代码:

1、加入这个变量记录当前B视图

```

代码块

@property (nonatomic, strong) UIViewController *presentingVC;

```



2、在B中加入重写:

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void(^)(void))completion

{

    if (self.presentedViewController)

    {

        if (self.presentingViewController) {

            self.presentingVC = self.presentingViewController;

        }

        [super dismissViewControllerAnimated:flag completion:completion];

    }

3、从B回到A代码:

if (self.presentingVC) {

          [self.presentingVC dismissViewControllerAnimated:YES completion:nil];

    }else{

           [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    }

重点->知识点讲解

 self.presentedViewController 是 self.present 出来的 modalVC

 self.presentingViewController 是 super.present 出来的 modalVC

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容