gpt4 book ai didi

ios - 带有 DatePicker 的 UITextField 崩溃

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

我是 iOS/Swift 的新手,所以请多多包涵。

我有一个 TextField、timeTextField,并希望在单击时显示一个 TimePicker。 All this is working property but when another element is selected the app crashes why does it crash?更新 1:更新代码代码:

func setupTimePicker(){
datePickerView.datePickerMode = UIDatePickerMode.time
datePickerView.removeFromSuperview()
timeTextField.inputView = datePickerView
datePickerView.addTarget(self, action: #selector(self.datePickerValueChanged(sender:)), for: .valueChanged)
}

func datePickerValueChanged(sender:UIDatePicker) {
var date = Date()
let calendar = Calendar.current

date = sender.date;

let hour = calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date)

timeTextField.text = String(format: "%02d", hour) + ":" + String(format: "%02d", minutes)
}

错误:

[TestApp.ViewController pickTime:]: unrecognized selector sent to instance 0x7f9305e08e20

最佳答案

iOS8/iOS9 , 当您将 View 添加为 inputViewUITextField应用程序崩溃。要解决崩溃问题,请在添加 datePicker 之前作为inputViewUITextField调用[<pickerView> removeFromSuperView] .这将解决崩溃问题。

关于ios - 带有 DatePicker 的 UITextField 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42927969/

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