每当我按下按钮时,我都会在 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/