简体   繁体   English

“无法识别的选择器发送到实例” swift

[英]“Unrecognized selector sent to instance” swift

I keep getting a “Unrecognized selector sent to instance” in the addButtonDidTouch function when ever I press the button.每当我按下按钮时,我都会在addButtonDidTouch函数中收到“无法识别的选择器发送到实例”。 I have no idea what I might be doing wrong.我不知道我可能做错了什么。

@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())
    }

the whole error im getting is我得到的整个错误是

[UITableViewController addButtonDidTouch:]: unrecognized selector sent to instance 0x7fba30612ce0 [UITableViewController addButtonDidTouch:]: 无法识别的选择器发送到实例 0x7fba30612ce0

In your storyboard you have not set the class of this UITableViewController subclass.在您的故事板中,您尚未设置此 UITableViewController 子类的类。 In IB, select the view controller, then visit the third tab over in the inspector.在 IB 中,选择视图控制器,然后访问检查器中的第三个选项卡。 You need to set the Class to be your class.您需要将 Class 设置为您的类。

I can tell because the error refers to UITableViewController not your custom subclass.我可以说是因为错误是指UITableViewController而不是您的自定义子类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM