gpt4 book ai didi

ios - "unrecognized selector sent to instance error"当首先编辑地址字段然后返回日期时间选择器时

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

我正在开发一个像这样的简单界面:

add event

时间、时长、电话、地址都是UITextfield,当点击Time UITextField时,会出现UIDatePicker的inputview,可以选择日期和时间。

问题是,如果我编辑地址文本字段,然后返回将弹出 UIDatepicker 的时间文本字段,应用程序将因错误而崩溃:

    *** Terminating app due to uncaught 
exception 'NSInvalidArgumentException',
reason: '-[WantFun.AddEventViewController dateTImeInputPressed:]
: unrecognized selector sent to instance 0x137001f30'

如果我编辑显示为数字的持续时间或电话,则不会出错,但是每次我编辑地址时,如果尝试输入时间表单,我就会出错。

这是我的代码:

class AddEventViewController: UIViewController {

// MARK: Properties

@IBOutlet weak var datePicker: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
let timeString = dateFormatter.stringFromDate(NSDate())

datePicker.text = timeString

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: Action

@IBAction func dateTimeInputPressed(sender: UITextField) {
let inputView = UIView(frame: CGRectMake(0, 0, self.view.frame.width, 240))


let datePickerView : UIDatePicker = UIDatePicker(frame: CGRectMake(0, 40, 0, 0))
datePickerView.datePickerMode = UIDatePickerMode.DateAndTime
datePickerView.minuteInterval = 5

inputView.addSubview(datePickerView) // add date picker to UIView

let doneButton = UIButton(frame: CGRectMake((self.view.frame.size.width/2) - (100/2), 0, 100, 50))
doneButton.setTitle("Done", forState: UIControlState.Normal)
doneButton.setTitle("Done", forState: UIControlState.Highlighted)
doneButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
doneButton.setTitleColor(UIColor.grayColor(), forState: UIControlState.Highlighted)

inputView.addSubview(doneButton) // add Button to UIView

doneButton.addTarget(self, action: "doneButton:", forControlEvents: UIControlEvents.TouchUpInside) // set button click event

sender.inputView = inputView
datePickerView.addTarget(self, action: Selector("handleDatePicker:"), forControlEvents: UIControlEvents.ValueChanged)

handleDatePicker(datePickerView) // Set the date on start.
}
func handleDatePicker(sender: UIDatePicker) {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
datePicker.text = dateFormatter.stringFromDate(sender.date)
}

func doneButton(sender:UIButton?)
{
datePicker.resignFirstResponder() // To resign the inputView on clicking done.
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

该错误的任何原因?谢谢。

最佳答案

您的代码/xib/ Storyboard中是否有错字?异常表示它找不到选择器 -[WantFun.AddEventViewController dateTImeInputPressed:](时间中的大写 I)并且您的类有方法 dateTimeInputPressed

关于ios - "unrecognized selector sent to instance error"当首先编辑地址字段然后返回日期时间选择器时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34001288/

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