@IBAction func tapDeleteButton(_ sender: UIButton) {
let alert = UIAlertController(title:"Are you sure?",message: "Do you really want to delete?",preferredStyle: UIAlertController.Style.alert)
let cancle = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alert.addAction(cancle)
present(alert, animated: true, completion: nil)
let delete = UIAlertAction(title: "Delete", style: .destructive){(_) in
let uuidString = self.diary?.uuidString
NotificationCenter.default.post(name: NSNotification.Name("deleteDiary"), object: uuidString, userInfo: nil)
}
alert.addAction(delete)
present(alert, animated: true, completion: nil)
}
你好。我在制作日記應用程式時正在快速學習。
但我堅持為單元格創建洗掉按鈕。
當我在警報中點擊洗掉時出現錯誤。
我如何處理帶有通知和警報的洗掉?
uj5u.com熱心網友回復:
問題是,您正試圖UIAlertController在當前呈現的UIAlertController.
您正在展示您的UIAlertController兩次。
洗掉present(alert, animated: true, completion: nil)下面的行let alert = ...。
uj5u.com熱心網友回復:
問題是因為,您已經提出了兩次警報
試試這個:
@IBAction func tapDeleteButton(_ sender: UIButton) {
let alert = UIAlertController(title:"Are you sure?",message: "Do you really want to delete?",preferredStyle: UIAlertController.Style.alert)
let cancle = UIAlertAction(title: "Cancel", style: .default, handler: nil)
let delete = UIAlertAction(title: "Delete", style: .destructive){(_) in
let uuidString = self.diary?.uuidString
NotificationCenter.default.post(name: NSNotification.Name("deleteDiary"), object: uuidString, userInfo: nil)
}
alert.addAction(cancle)
alert.addAction(delete)
present(alert, animated: true, completion: nil)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/425794.html
上一篇:我怎樣才能很好地對齊它們?
