Tuesday, 14 March 2017

Alert Controller navigating to another New View (Swift3)

//*************** Alert Controller ***************//

@IBAction func btnAlertAction(_ sender: Any)
{
   
let alertActionSheet = UIAlertController(title: "Menu", message: "",
preferredStyle: .alert)
       
       
let oneAction = UIAlertAction(title: "One", style: .default, handler: { action in self.performSegue(withIdentifier: "mySegueIdentifierOne", sender: self) })
       
let twoAction = UIAlertAction(title: "Two", style: .default, handler: { action in self.performSegue(withIdentifier: "mySegueIdentifierTwo", sender: self) })
  
let closeAction = UIAlertAction(title: "Close", style: .cancel, handler: { action in print("Close")
        })
       
        alertActionSheet.addAction(closeAction)
        alertActionSheet.addAction(oneAction)
        alertActionSheet.addAction(twoAction)

 self.present(alertActionSheet, animated: true)
}


# Note

1. Create Outlet first

2. Create Action Button & write above code

3.  You could create a segue in your storyboard, control dragging from the yellow view controller at
      the top of a scene to a new view controller. Then give that segue an identifier in the inspector. You
      can call that from the handler in your code.

4. If you don't need title of Alert controller use below code

            alertActionSheet.title = nil
          alertActionSheet.message = nil

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home