Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过“取消”和“保存”按钮操作,快速时间选择器显示到UIAlerController中_Ios_Swift - Fatal编程技术网

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