【发布时间】:2023-03-30 12:02:01
【问题描述】:
在应用程序中,当我点击UITextField 时,应该给我一个UIDatePicker,但在将iPhone 更新为iOS 13 时却没有显示UIDatePicker。 适用于 iOS 12+ 版本。
我正在研究最新的Xcode 11 和macOS Mojave 10.14.6
这是我正在使用的代码:
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
let dateString: String!
activeTextField = textField
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
if activeTextField == fromDateTextField && fromDateTextField.text != "" {
dateString = fromDateTextField.text
let date = dateFormatter.date(from: dateString!)
datePickerView.setDate(date!, animated: false)
} else if activeTextField == toDateTextField && activeTextField.text != "" {
dateString = toDateTextField.text
let date = dateFormatter.date(from: dateString!)
datePickerView.setDate(date!, animated: false)
}
UIView.animate(withDuration: 0.3) {
self.datePickerContainerView.frame = CGRect(x: 0,
y: UIScreen.main.bounds.size.height - 250,
width: UIScreen.main.bounds.size.width,
height: 250)
}
return false
}
【问题讨论】:
-
这段代码不是你应该做的来显示一个选择器视图。只需让选择器查看文本字段的
inputView。而已。显示选择器视图不需要额外的代码。 -
对不起,这没有帮助。上面的代码(附有问题)在 iOS 12 设备中运行良好。只面临 iOS 13 的问题。
-
没有帮助是什么意思?您在任何版本的 iOS 中都做错了。正确操作,它将适用于所有版本的 iOS。
-
Simply make the picker view the inputView of text field- 似乎没有做任何改变。在点击文本字段时,没有任何反应。 -
你在哪里设置了文本字段的
inputView?应该在viewDidLoad完成。
标签: ios swift datepicker ios13