如何在swift中实现删除通知?所以如果我有一个删除按钮,你确定""通知框弹出删除和取消选项,我以为它会在info.plist中,但没有看到任何东西,任何人都可以帮忙吗?
答案 0 :(得分:0)
简单只需使用IBAction
将您的按钮链接到您的代码,然后在函数中编写警报代码。
所以你的代码应该是这样的:
class ViewController: UIViewController {
@IBAction func showAlertButtonTapped(_ sender: UIButton) {
// create the alert
let alert = UIAlertController(title: "UIAlertController", message: "Would you like to continue learning how to use iOS alerts?", preferredStyle: UIAlertControllerStyle.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: "Continue", style:
UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
}
答案 1 :(得分:0)
快速4
@IBAction func DeleteButtonTapped(_ sender: UIButton) {
let DeleteAlert = UIAlertController(title: "Alert", message: "Request will be deleted", preferredStyle: UIAlertControllerStyle.alert)
DeleteAlert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in
//Add your Action for deleting
}))
DeleteAlert.addAction(UIAlertAction(title: "Cancel",style: .cancel, handler: { (action: UIAlertAction!) in
//if anything to do after cancel clicked
}))
present(DeleteAlert, animated: true, completion: nil)
}