gpt4 book ai didi

ios - donePicker : unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 16:16:26 25 4
gpt4 key购买 nike

我在我的 ios 应用程序的 UIpickerView 上添加了取消和完成按钮,但我收到错误,如 - [Avakaash.Profile_add_update donePicker]: unrecognized selector sent to instance 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
}

我的 Controller 类看起来像-

 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)

最佳答案

你忘记实现 donePickercanclePicker 按钮的 Action 了

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

喜欢的 Action

func donePicker () //Create an IBAction
{
// do something

}

func canclePicker () //Create an IBAction
{
// do something

}

关于ios - donePicker : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39017569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com