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彻底消失后再执行切换根控制器,解决!

 

posted @ 2015-09-09 17:26  攻城狮~2022  阅读(620)  评论(0编辑  收藏  举报
所有内容都是自己使用过程的总结,如有不严谨或者不正确的地方,麻烦大家留言指出,一起研讨。