donePicker:发送到实例的无法识别的选择器
donePicker: unrecognized selector sent to instance
我在我的 ios 应用程序的 UIpickerView 顶部添加了取消和完成按钮,但我收到类似以下的错误- [Avakaash.Profile_add_update donePicker] : 无法识别的选择器发送到实例 0x7faf19daf1f0' 我的代码如下所示-
override func viewDidLoad() {
super.viewDidLoad()
std_class_pickerView.tag = 0
country_pickerview.tag = 1
std_class_pickerView = UIPickerView(frame: CGRectMake(0, 200, view.frame.width, 300))
std_class_pickerView.backgroundColor = .whiteColor()
std_class_pickerView.showsSelectionIndicator = true
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.Default
toolBar.translucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("donePicker"))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("canclePicker"))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.userInteractionEnabled = true
std_class_pickerView.delegate = self
text_std_class.inputView = std_class_pickerView
text_std_class.inputAccessoryView = toolBar
}
我的控制器 class 看起来像-
class Profile_add_update: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
}
错误日志-
[Avakaash.Profile_add_update donePicker]: unrecognized selector sent to instance 0x7faf19daf1f0
2016-08-18 17:04:13.653 Avakaash[2999:227329] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'- [Avakaash.Profile_add_update donePicker]: unrecognized selector
sent to instance 0x7faf19daf1f0'
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
您忘记执行 donePicker
的操作并且 canclePicker
按钮喜欢
func donePicker () //Create an IBAction
{
// do something
}
func canclePicker () //Create an IBAction
{
// do something
}
完整代码
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.Default
toolBar.translucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style:.Plain, target: self, action: #selector(ViewController.donePicker))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style:.Plain, target: self, action: #selector(ViewController.canclePicker))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.userInteractionEnabled = true
点赞
func donePicker () //Create an IBAction
{
// do something
}
func canclePicker () //Create an IBAction
{
// do something
}
您似乎已将此问题 () 的答案剪切并粘贴到您的应用程序中,但并未了解其工作原理。这不是学习如何编写代码的好方法。
错误消息告诉您您正在尝试调用名为 "donePicker" 的选择器(或函数或操作),但不存在这样的选择器。您需要在 class 中创建一个名为 "donePicker" 的操作(还有一个名为 "canclePicker"(原文如此。)),您的代码才能正常工作。
我在我的 ios 应用程序的 UIpickerView 顶部添加了取消和完成按钮,但我收到类似以下的错误- [Avakaash.Profile_add_update donePicker] : 无法识别的选择器发送到实例 0x7faf19daf1f0' 我的代码如下所示-
override func viewDidLoad() {
super.viewDidLoad()
std_class_pickerView.tag = 0
country_pickerview.tag = 1
std_class_pickerView = UIPickerView(frame: CGRectMake(0, 200, view.frame.width, 300))
std_class_pickerView.backgroundColor = .whiteColor()
std_class_pickerView.showsSelectionIndicator = true
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.Default
toolBar.translucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("donePicker"))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("canclePicker"))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.userInteractionEnabled = true
std_class_pickerView.delegate = self
text_std_class.inputView = std_class_pickerView
text_std_class.inputAccessoryView = toolBar
}
我的控制器 class 看起来像-
class Profile_add_update: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
}
错误日志-
[Avakaash.Profile_add_update donePicker]: unrecognized selector sent to instance 0x7faf19daf1f0
2016-08-18 17:04:13.653 Avakaash[2999:227329] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'- [Avakaash.Profile_add_update donePicker]: unrecognized selector
sent to instance 0x7faf19daf1f0'
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
您忘记执行 donePicker
的操作并且 canclePicker
按钮喜欢
func donePicker () //Create an IBAction
{
// do something
}
func canclePicker () //Create an IBAction
{
// do something
}
完整代码
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.Default
toolBar.translucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style:.Plain, target: self, action: #selector(ViewController.donePicker))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style:.Plain, target: self, action: #selector(ViewController.canclePicker))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.userInteractionEnabled = true
点赞
func donePicker () //Create an IBAction
{
// do something
}
func canclePicker () //Create an IBAction
{
// do something
}
您似乎已将此问题 (
错误消息告诉您您正在尝试调用名为 "donePicker" 的选择器(或函数或操作),但不存在这样的选择器。您需要在 class 中创建一个名为 "donePicker" 的操作(还有一个名为 "canclePicker"(原文如此。)),您的代码才能正常工作。