【问题标题】:how can I implement a "delete" notification in swift如何在 swift 中实现“删除”通知
【发布时间】:2018-06-10 03:39:20
【问题描述】:

如何在 swift 中实现删除通知?因此,如果我有一个删除按钮,会弹出带有删除和取消选项的“你确定”通知框,我认为它会在 info.plist 中但没有看到任何内容,有人可以帮忙吗?

【问题讨论】:

  • 我还没有,我知道如何执行删除操作,但我只是不知道如何在按下按钮后弹出通知
  • 不清楚你在问什么。你需要更好地解释。我想你已经定义了一个推送通知,告诉你应用程序删除一些东西?并且您想向用户显示一条消息,要求他们确认删除操作?如果是这样,您遇到问题的哪一部分?
  • 抱歉不清楚,我想要一个在按下删除按钮时弹出的通知,这是苹果标准的通知之一,上面写着“你确定要删除”,有 2 个选项“删除”和“取消”,我不知道如何设置通知。希望更清楚
  • 您确定要通知吗?你不想要某种模式对话框吗?示例:stackoverflow.com/questions/25511945/…
  • 是的,这正是我想要的,我不知道那些叫什么谢谢

标签: ios swift apple-push-notifications


【解决方案1】:

很简单只需使用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)
        }

}

【讨论】:

    【解决方案2】:

    在 Swift 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)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      相关资源
      最近更新 更多