我有一個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」
能否請您詳細闡述更多...得到了由答案 –
困惑讓我修改,以顯示你應該叫方法 –