Pan Pipatpunlop Pan Pipatpunlop - 4 months ago 23
Swift Question

Swift - push alert action to show new ViewController

How to show or link to new ViewController when push button on alert?

enter image description here

This is my code

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)
self.present(alert, animated: true, completion: nil)


Control drag from View Controller 1 (The yellow dot) to any where on View Controller 2 and then click on the Segue. Show the Attributes inspector and Under Storyboard Segue identifier name the identifier VC2

If this is the answer you were looking for don't forget to except the answer.

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)

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