2016-10-19 5 views
1

アラートを押したときに新しいViewControllerを表示またはリンクする方法は?新しいViewControllerを表示するためのスワイププッシュアラート操作

enter image description here

これは、ビューコントローラ2上の任意の場所にビューコントローラ1(黄色のドット)から自分のコード

let alert = UIAlertController(title: validateQRObj.responseDescription, message: validateQRObj.productName, preferredStyle: .alert) 
let action = UIAlertAction(title: "OK", style: .default) { (action) -> Void in 
    let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ProductDetialViewController") 
    self.present(viewController!, animated: true, completion: nil) 
} 
alert.addAction(action) 
self.present(alert, animated: true, completion: nil) 
+4

投稿したコードにはどのような問題がありますか? – rmaddy

答えて

0

コントロールをドラッグし、次にセグエをクリックしてください。属性インスペクタとアンダーストーリーボードを表示するSegue識別子の名前識別子VC2

これが答えだったら答えを忘れないでください。

func alert(){ 

    let alertController = UIAlertController(title: "Open View Controller. ", message: "Press Ok to open View Controller number 2.", preferredStyle: UIAlertControllerStyle.alert) 
    let ok = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) -> Void in 
    //The (withIdentifier: "VC2") is the Storyboard Segue identifier. 
    self.performSegue(withIdentifier: "VC2", sender: self) 
}) 

    alertController.addAction(ok) 
    self.present(alertController, animated: true, completion: nil) 
} 
+0

それは仕事です!ありがとうございました –

0

私にとってはうまくいきません。私は作った:

func alert(){ 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let twop = storyboard.instantiateViewController(withIdentifier: "Accueil") as! Accueil 
    let alertController = UIAlertController(title: "Open new View !", message: "Clic to ok", preferredStyle: UIAlertControllerStyle.alert) 
    let ok = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) -> Void in 
     self.navigationController?.show(twop, sender: self) 
    }) 

    alertController.addAction(ok) 
    self.present(alertController, animated: true, completion: nil) 
} 

そして今それは働いている!

関連する問題