swift - 通过alert.addAction 使用未解析的标识符

标签 swift alert uialertaction

我的alert.addAction() 出现错误。看来我的项目不知道在哪里可以找到它,对吗?

我创建了一个没有按钮的警报,现在我正在尝试向其添加按钮。

这是我的警报窗口和添加按钮的代码:

func naamInModelChangedHandler ( notification:NSNotification ) {
    println("De naam in de model is veranderd naar \(model.naam!)")
    NSNotificationCenter.defaultCenter().removeObserver(
                self,
                name: "NAAM_CHANGED",
                object: model)

    let alert = UIAlertController(title: "Ola", message: "De naam is gewijzigd", preferredStyle: UIAlertControllerStyle.Alert)

    self.presentViewController(alert, animated: true, completion: nil)

    alert.addAction(okAction)
    alert.addAction(cancelAction)

}

我创建了一个名为 AlertController 的 UIAlertAction,并使用一些代码来制作按钮。

let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (action) -> Void in
    println("Ok geklikt")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (action) -> Void in
    println("Cancel geklikt")
}

但我认为它似乎不知道去哪里寻找。我在这里做错了什么?

最佳答案

这样做

func naamInModelChangedHandler ( notification:NSNotification ) {
    println("De naam in de model is veranderd naar \(model.naam!)")
    NSNotificationCenter.defaultCenter().removeObserver(
                self,
                name: "NAAM_CHANGED",
                object: model)

   let alert = UIAlertController(title: "Ola", message: "De naam is gewijzigd", preferredStyle: UIAlertControllerStyle.Alert)

    self.presentViewController(alert, animated: true, completion: nil)

   let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (action) -> Void in

    println("Ok geklikt")
   }

  let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (action) -> Void in

    println("Cancel geklikt")
  }

    alert.addAction(okAction)
    alert.addAction(cancelAction)

}

关于swift - 通过alert.addAction 使用未解析的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30303262/

相关文章:

ios - Swift - 如何从语音保存文本文件

ios - 如何让detailViewController 在Swift 的masterViewController.tableView 中显示上一行或下一行的detailItem?

ios - Objective-C - 我希望 UIAlertController 在单击按钮时不被删除

ios - UIAlertController - 如果第一次解除警报,则不会执行操作

ios - 在聊天应用程序中使用带有 contentoffset 的 uitableview 进行延迟加载

ios - 安排通知每天在 X h :Y s and redirect to specific View 触发

javascript - 通过 JavaScript 根据提交结果更改网页内容

javascript - 在警告框中转储 jquery 对象

ios - 如何处理用户选择通知设置权限警报

ios - 如何使用 alert 来确认或取消 View 转换?