I\'m trying to make an Alert Controller in which, if the Answer is \"Ok\", then it will perform a segue to a MapView. Here\'s the full code:
@IBAction func teste
So to fix the presentViewController(ViewController, animated: true, completion: nil)
function in the okConfirmAction
closure, try this:
self?.present(ViewController(), animated: true, completion: nil)
And for the performSegue(withIdentifier:sender:)
function in the okConfirmAction
closure, try:
self?.performSegue(withIdentifier: "teste", sender: self)
As it is a closure you have to use self before calling the function. This is to make you aware that you may cause a retain cycle.
Write the closure as follows to prevent the retain cycle (using a weak self
reference means we replace self
with self?
as a prefix for present(_:animated:completion:)
and performSegue(withIdentifier:sender:)
):
let okConfirmAction = UIAlertAction(title:"Sim", style: UIAlertActionStyle.default, handler:{ [weak self] (alert:UIAlertAction) -> Void in
//insert code from above
})