我有一个UIAlertController实例,一旦用户点击一个按钮就会弹出给用户。用户将在警报视图中输入他/她的全名,然后按确认。我将这个值存储到数据库中。Swift - UIAlertController post action
我想在保存操作在数据库中完成时显示另一个警报控制器。我试图在通话的完成部分做到这一点,但没有奏效。这里是我试过的代码:
@IBAction func changeNamePressed(sender: AnyObject) {
let alertController = UIAlertController(title: "Change Full Name", message: "Please enter your name as you want it displayed in your profile", preferredStyle: .Alert)
let confirmAction = UIAlertAction(title: "Confirm", style: .Default) { (_) in
if let field = alertController.textFields![0] as? UITextField {
// store your data
self.userObject.name = field.text
self.nameLabel.text = field.text
SwiftSpinner.show("Updating Full Name")
let errorFound: NSError? = self.utilities.changeFullName(field.text!)
SwiftSpinner.hide()
if(errorFound?.domain != "")
{
print("Error Updating Name Change: \(errorFound?.description)")
}else{
print("No Errors Found")
}
} else {
// user did not fill field
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (_) in }
alertController.addTextFieldWithConfigurationHandler { (textField) in
textField.placeholder = "Your Full Name"
}
alertController.addAction(confirmAction)
alertController.addAction(cancelAction)
self.presentViewController(alertController, animated: true, completion: displayNameChangeConfirmation)
}
func displayNameChangeConfirmation()
{
let alert = UIAlertController(title: "Profile Updated", message: "Your full name has been successfully updated.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
在执行上面的代码时,我得到这个错误:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
任何想法是怎么回事,它如何能解决吗?我应该采取不同的方法吗?
感谢,从完成任务的方法“displayNameChangeConfirmation”
能否请您详细阐述更多...得到了由答案 –
困惑让我修改,以显示你应该叫方法 –