Ios 通过“取消”和“保存”按钮操作,快速时间选择器显示到UIAlerController中
在我的场景中,我尝试在Ios 通过“取消”和“保存”按钮操作,快速时间选择器显示到UIAlerController中,ios,swift,Ios,Swift,在我的场景中,我尝试在UIAlertController中使用取消和保存按钮操作显示计时器(仅显示HH:MM和am或PM)。我尝试了下面的代码,但它不工作 let myDatePicker: UIDatePicker = UIDatePicker() myDatePicker.timeZone = NSTimeZone.local myDatePicker.frame = CGRect(x: 0, y: 15, width: 270, height: 200) let a
UIAlertController
中使用取消和保存按钮操作显示计时器(仅显示HH:MM和am或PM)。我尝试了下面的代码,但它不工作
let myDatePicker: UIDatePicker = UIDatePicker()
myDatePicker.timeZone = NSTimeZone.local
myDatePicker.frame = CGRect(x: 0, y: 15, width: 270, height: 200)
let alertController = UIAlertController(title: "\n\n\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertController.Style.alert)
alertController.view.addSubview(myDatePicker)
let selectAction = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: { _ in
print("Selected Date: \(myDatePicker.date)")
})
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: nil)
alertController.addAction(selectAction)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion:{})
使用下线修复了此问题
myDatePicker.datePickerMode = .time