[UIApplication sharedApplication].keyWindow.rootViewController

來源:互聯網
上載者:User

標籤:mod   應用   dex   地方   使用者   show   變數   model   sha   

一般來說 [UIApplication sharedApplication].keyWindow.rootViewController 會在 appDelegate 中初始化,並且整個應用運行過程中都不會變。

 

所以在很多地方需要用 presentModelViewController 方法時,用這個 rootViewController 是很方便的,因為它相當於一個全域變數,無需再申請、釋放。

 

但是本人在使用過程中發現有 rootViewController 被改為 nil 的情況。

 

分析後發現,當 UIAlertView 調用 show 方法後,rootViewController 會被改為 nil,當它 dismiss 後又改回去。而我需要使用者在點擊 alertview 上的按鈕後再做

presentModelViewController 的操作。

 

解決方案:

不要使用 alertview delegate 中的 

- (void)alertView:clickedButtonAtIndex:

方法

 

而要用:

- (void)alertView:diddismissWithButtonAtIndex:

方法!

[UIApplication sharedApplication].keyWindow.rootViewController

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.