OGeek|极客世界-中国程序员成长平台

标题: ios - Action 表中的 UIDatePicker 不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:42
标题: ios - Action 表中的 UIDatePicker 不起作用

我正在尝试在操作表中显示 UIDatePicker,但它不起作用。

这是我的代码。单击按钮时,我已经编写了此代码

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message"\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];

UIView *datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
[datePickerView setBackgroundColor:[UIColor clearColor]];

CGRect pickerFrame = CGRectMake(0, 0, self.view.frame.size.width, 200);
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[datePicker setDatePickerMode:UIDatePickerModeDate];

[datePickerView addSubview:datePicker];
[alertController.view addSubview:datePicker];

UIAlertAction* alertAction = [UIAlertAction actionWithTitle"OK" style:UIAlertActionStyleDefault                                                           handler:^(UIAlertAction * action) {


}];

[alertController addAction:alertAction];

[self.view.window.rootViewController presentViewController:alertController animated:YES completion:nil];

[alertAction setValue:[UIColor redColor] forKey"titleTextColor"];

这是更新后的代码。在模拟器中运行时它工作正常,但在设备中工作时我无法单击确定按钮(uialertaction)...尝试单击确定按钮选择器时正在连续滚动



Best Answer-推荐答案


由于 UIActionSheetiOS 8.3 中已弃用,您需要使用 Apple 提供的文档和指南在屏幕中添加 DatePicker。 p>

Apple 引入了内联日期选择器(如日历应用程序日期选择器)的使用。

使用下面的 github 代码进行内联日期选择器

链接: https://github.com/DylanVann/DatePickerCell

供引用: iOS 7 - How to display a date picker in place in a table view?

关于ios - Action 表中的 UIDatePicker 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41825929/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4