我正在尝试在操作表中显示 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)...在尝试单击“确定”按钮时选择器不断滚动
最佳答案
作为UIActionSheet
在 iOS 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/