如何解决donePicker 无法识别的选择器发送到实例 UiTextField
我只是在键盘上为 UiTextField
添加了一个完成的工具栏
完成点击我面对
unrecognized selector sent to instance
错误:
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,selector: #selector(keyboardWillShow),name: UIResponder.keyboardWillShowNotification,object: nil)
NotificationCenter.default.addObserver(self,selector: #selector(keyboardWillHide),name: UIResponder.keyboardWillHideNotification,object: nil)
self.addDoneButtonOnKeyboard()
}
@IBOutlet weak var betTextField: UITextField!
func addDoneButtonOnKeyboard(){
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0,y: 0,width: UIScreen.main.bounds.width,height: 50))
doneToolbar.barStyle = .default
let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace,target: nil,action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "Done",style: .done,target: self,action: #selector(BetViewController.doneAction))
let items = [flexSpace,done]
doneToolbar.items = items
doneToolbar.sizeToFit()
betTextField.inputAccessoryView = doneToolbar
}
@objc func doneAction() {
betTextField.resignFirstResponder()
}
BetViewController
由 StoryBoardID 添加。
我错过了什么?
错误信息:
Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '-[Bet.BetViewController betTexField:]: unrecognized selector sent to instance 0x7ffa0c860e00'
terminating with uncaught exception of type NSException
CoreSimulator 732.18.6 - Device: iPhone 12 Pro Max (4549AD60-8D64-44E7-B2D6-C347655A1DA6) - Runtime: iOS 14.3 (18C61) - DeviceType: iPhone 12 Pro Max
解决方法
在 StoryBoard 中,我刚刚删除了一个未使用的已发送事件“Editing Did End”。
不再与 Done ToolBar 发生冲突。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。