UIAlertController in Core Data by Tutorials

This compiles and runs but does not do anything. Have looked at other solutions on web but so far all are out of date.

@IBAction func rate(_ sender: AnyObject) {
let alert = UIAlertController(title: “New Rating”,
message: “Rate this bow tie”,
preferredStyle: .alert)
alert.addTextField { (textField) in
textField.keyboardType = .decimalPad
}
let cancelAction = UIAlertAction(title: “Cancel”,
style: .default)
let saveAction = UIAlertAction(title: “Save”,
style: .default) {
[unowned self] action in
guard let textField = alert.textFields?.first else {
return
}
self.update(rating: textField.text)
}
alert.addAction(cancelAction)
alert.addAction(saveAction)
present(alert, animated: true)
}

Is your IBAction rate connected with the “Touch Up Inside” Sent Event of the Rate UIButton? Exectly the same code work in my case in the BowTie project and pops up the dailog as expected.

@datahog. Thanks very much for your question, and my apologies for the delayed reply! If your code that you posted is correctly entered, then I would concur with @tetanuss that most likely your IBOutlet has not been connected to the action method that should be triggered by the button. If they are indeed connected, try putting a break point at this method to ensure that it is being called by the UIButton in question.

I hope this helps. :slight_smile:

All the best!