在我的场景中,我试图在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
关于ios - Swift TimePicker通过取消和保存按钮操作显示到UIAlerController中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57303838/