2015-11-09 42 views
0

上呈現 我想顯示警告而不是跳轉到主頁面,但它沒有跳轉並顯示此警告: 嘗試對 <SignUpViewController>提出 <UITabBarController>這已經是呈現 <UIAlertController> Swift - 警告:嘗試在已呈現<UIAlertController>

這裏是我的代碼

let alertController = UIAlertController(title: "Success", message: "Back", preferredStyle: UIAlertControllerStyle.Alert) 

alertController.addAction(UIAlertAction(title: "true", style: UIAlertActionStyle.Default,handler: nil)) 
self.presentViewController(alertController, animated: true, completion:nil) 

let MyPage = self.storyboard?.instantiateViewControllerWithIdentifier("tabBarController") 
presentViewController(MyPage!, animated: true, completion: nil) 

我看到一些答案讓我用viewdidappear什麼的,但我仍然困惑,不知道該怎麼辦那我花了好幾個小時沒有,請幫我修好是問題,非常感謝!

+0

當u刪除 「presentViewController(我的空間....)」,做了警戒工作? – rnsjtngus

+0

@rnsjtngus警報正在工作,但Mypage沒有顯示 –

+0

把presentViewController函數調用在警報完成處理程序 – rnsjtngus

回答

1

你可以把UR presentViewController功能警報完成處理

alertController.addAction(UIAlertAction(title: "true", style: UIAlertActionStyle.Default,handler: nil)) 

如果ü把在處理一些代碼,當u單擊「真」按鈕執行的代碼。

例如,

alertController.addAction(UIAlertAction(title: "true", style: UIAlertActionStyle.Default,handler: { 
    (alert: UIAlertAction) -> Void in 
    let MyPage = self.storyboard?.instantiateViewControllerWithIdentifier("tabBarController") 
    self.presentViewController(MyPage!, animated: true, completion: nil) 
})) 
+0

如果有幫助,請選擇回答plz – rnsjtngus

相關問題