ios - “Unrecognized selector sent to instance” swift

标签 ios swift xcode

每当我按下按钮时,我都会在 addButtonDidTouch 函数中收到“Unrecognized selector sent to instance”。我不知道我可能做错了什么。

@IBAction func addButtonDidTouch(_ sender: AnyObject) {
    let alert = UIAlertController(title: "Grocery Item",
                                  message: "Add an item to the list",
                                  preferredStyle: .alert)

    let saveAction = UIAlertAction(title: "Save",
                                   style: .default) { action in
       guard let textField = alert.textFields?.first,
        let text = textField.text else { return }

        let listItem = ListItem(name: text, addedByUser: self.user.email, completed: false)

        let listItemRef = self.ref.child(text.lowercased())

        listItemRef.setValue(listItem.toAnyObject())
    }

我得到的整个错误是

[UITableViewController addButtonDidTouch:]: unrecognized selector sent to instance 0x7fba30612ce0

最佳答案

在您的 Storyboard 中,您尚未设置此 UITableViewController 子类的类。在 IB 中,选择 View Controller ,然后访问检查器中的第三个选项卡。您需要将类(class)设置为您的类(class)。

我知道是因为错误指的是 UITableViewController 而不是您的自定义子类。

关于ios - “Unrecognized selector sent to instance” swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40028347/

相关文章:

uitableview - 在自定义 UITableViewCell 中点击按钮时如何更改 View

iphone - “无法读取符号”错误

xcode - OpenCV:未授权捕获视频 OpenCV:相机未能正确初始化

iphone - iOS5 UIButton 我应该尝试优化背景图片吗?

ios - 在 iO 中安装工具链配方时出现问题

ios - 为什么这个 OpenGL ES 2.0 着色器不能与我在 iOS 上的 VBO 一起使用?

ios - xcode 8 和 swift 3 - PHPhotoLibrary.requestAuthorization 崩溃

ios - 通过按钮从不同的 View 更新标签

ios - 有谁知道 Parse.com 文档发生了什么事?

ios - 从 ios 到 watchOS 的数据传输速率(发送或接收数据所需的时间)