ios - 操作表内的 UIDatePicker 不工作

标签 ios objective-c 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)...在尝试单击“确定”按钮时选择器不断滚动

最佳答案

作为UIActionSheetiOS 8.3 中已弃用您需要按照 Apple 提供的文档和指南添加 DatePicker在你的屏幕上。

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

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

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

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

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

相关文章:

ios - 使用 TPKeyboardAvoiding 类时 UITextField 弹出太高

ios - 双问号,它是如何工作的?

iphone - 如何以编程方式设置导航栏的位置

ios - IQKeyboardManager 从 UITextField 导航到 UITextView

ios - 观察 UIDatePicker 中是否命中了最小或最大日期

iphone - 删除/隐藏 UIDatePicker 的最小/最大日期范围之外的行?

ios - 在 iOS 上解析 XML

objective-c - Objective-C 中 static const 和 #define 的区别

objective-c - 是否可以像音乐应用程序或 ITunesU 那样将轨道标题添加到 "Now Playing Controls"菜单?

swift - 可折叠表格单元格 [Swift 3]