2015-12-11 41 views
-1

我提出了一個UIAlertController,出現大約半秒鐘後消失,然後我需要觸摸OK按鈕。 任何有關可能導致此問題的想法?UIAlertController瞬間消失

僅供參考,代碼如下,我過去多次使用過它。除此之外,我傳遞一個調用者參數。

func showMessageBox(msg:String, title:String, caller:UIViewController) { 
    let attribMsg = NSAttributedString(string: msg, 
     attributes: [NSFontAttributeName : UIFont.systemFontOfSize(23.0)]) 
    let userPopUp = UIAlertController(title:title, 
     message:nil, preferredStyle:UIAlertControllerStyle.Alert) 
    userPopUp.setValue(attribMsg, forKey: "attributedMessage") 
    userPopUp.addAction(UIAlertAction(title:"OK", style:UIAlertActionStyle.Default, 
     handler:{action in})) 
    caller.presentViewController(userPopUp, animated: true, completion: nil) 
} 
+4

分享代碼請 –

+0

顯示如何預編碼的代碼 –

+0

我編輯了問題以添加代碼。 – Michel

回答

0

我剛剛試過這裏的代碼,它工作正常 - 警報控制器等待我離開前點擊按鈕。是否有可能會出現這種情況也會意外地解僱它?或者也許caller裏的視圖控制器本身就被解僱了?

+0

調用者內部的視圖控制器不會被解僱,因爲當彈出消失時,它仍然存在。 – Michel

+0

你不是在一些奇怪的時間,例如在'viewDidLoad()'?如果您嘗試在錯誤的時間顯示視圖控制器,您應該在Xcode日誌中看到警告。 – TwoStraws

+0

我不是從控制器本身呈現彈出式窗口,而是從它所調用的委託方法呈現。 – Michel