iOS開發報錯之attempt to dismiss modal view controller whose view does not currently appear

剛纔遇到一個問題,如今在這就當紀錄一下,你們有遇到的能快速找到緣由,分享一下啊。app

在APP中,須要用戶登陸後才能使用,因此我經過更改APP的[UIApplicationsharedApplication].keyWindow.rootViewController來控制界面的跳轉。spa

在使用過程當中出現以下問題:代理

1.登陸成功後點擊註銷按鈕,彈出註銷提示框UIAlertView;it

2.註銷成功後從新登陸;io

3.再次點擊註銷再也不彈出UIAlertView。class

提示以下警告:登錄

點擊註銷按鈕執行更改rootvie操做:cli

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

再次點擊註銷的時候提示:d3

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完全消失後再執行切換根控制器,解決!

相關文章
相關標籤/搜索