zoukankan      html  css  js  c++  java
  • iOS开发报错之attempt to dismiss modal view controller whose view does not currently appear

    刚才遇到一个问题,现在在这就当纪录一下,大家有遇到的能快速找到原因,分享一下啊。

    在APP中,需要用户登录后才能使用,所以我通过更改APP的[UIApplicationsharedApplication].keyWindow.rootViewController来控制界面的跳转。

    在使用过程中出现如下问题:

    1.登录成功后点击注销按钮,弹出注销提示框UIAlertView;

    2.注销成功后重新登录;

    3.再次点击注销不再弹出UIAlertView。

    提示如下警告:

    点击注销按钮执行更改rootvie操作:

    attempt to dismiss modal view controller whose view does not currently appear

    再次点击注销的时候提示:

    Attempt to present <_UIModalItemsPresentingViewController: 0x7f9d1b5b2fd0> on <_UIModalItemAppViewController: 0x7f9d1d335520> whose view isnot in the window hierarchy!

    我的代码是:

        LoginViewController *loginVC = [[LoginViewControllerallocinit];

                CNavigationController *nav = [[CNavigationControllerallocinitWithRootViewController:loginVC];

                [UIApplicationsharedApplication].keyWindow.rootViewController = nav;

    造成这个的原因主要是

      因为我执行上述代码是在:-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex的这个方法执行的;

      所以在我执行切换根视图控制器的时候UIAlertView是还没有消失的,所以会出现上述错误,UIAlertView的消失是需要一定的时间的,

    解决方案:

    要解决这个问题,就是在UIAlertView的另一个代理方法-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex中执行切换根 控制器的操作,即上述我的代码,也就是说在UIAlertView彻底消失后再执行切换根控制器,解决!

     

    本篇内容是参考网络教程学习过程中的笔记
    开发工作着,生活快乐着,留下总结,相互交流,共同进步
  • 相关阅读:
    ERStudio的使用
    AWK文本处理工具(Linux)
    SubSonic3.0.0.4.1源码包与调用Dll
    实现简单微博功能!(上)
    缓冲区溢出攻击
    移动收入超PC端 盛大文学战略转型初见成效
    Windows错误码解析
    获取Windows操作系统的CPU使用率以及内存使用率
    关于32位程序在64位系统下运行中需要注意的重定向问题(有图,很清楚)
    API Monitor简介(API监控工具)
  • 原文地址:https://www.cnblogs.com/lovechengyu/p/4795397.html
Copyright © 2011-2022 走看看