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

來源:互聯網
上載者:User

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! My Code是:     LoginViewController *loginVC = [[LoginViewControlleralloc] init];             CNavigationController *nav = [[CNavigationControlleralloc] initWithRootViewController:loginVC];             [UIApplicationsharedApplication].keyWindow.rootViewController = nav; 造成這個的原因主要是:   因為我執行上述代碼是在:-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex的這個方法執行的;   所以在我執行切換根視圖控制器的時候UIAlertView是還沒有消失的,所以會出現上述錯誤,UIAlertView的消失是需要一定的時間的, 解決方案: 要解決這個問題,就是在UIAlertView的另一個代理方法-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex中執行切換根 控制器的操作,即上述My Code,也就是說在UIAlertView徹底消失後再執行切換根控制器,解決!  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.