Reputation: 57
I'm trying to pop the controller from an alert action and getting to another view controller. I want to do some action immediately after I get on to this other controller, say open another alert controller. How do I do it?
UIAlertController.getAlertView("Success", message: "Your password has been successfully changed!", cancelButtonTitle: "Ok", cancelHandler: { (action) in
self.navigationController?.popViewController(animated: true)
}).show(self)
Upvotes: 1
Views: 613
Reputation: 379
If you want to go back to previous viewController on click of alert action then below code will help you.
let alert = UIAlertController(title: "Success", message: "Your password has been successfully changed!", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: { action in
//perfoem any action you want on click of OK
self.navigationController?.popViewController(animated: true)
}))
self.present(alert, animated: true, completion: nil)
Upvotes: 1