我正在尝试在操作表中显示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)...尝试单击确定按钮选择器正在连续滚动
答案 0 :(得分:0)
UIActionSheet
已弃用iOS 8.3
,您需要使用Apple提供的文档和指南在屏幕中添加DatePicker
。
Apple推出了使用内联日期选择器(如日历应用日期选择器)。
使用下面的github Code for Inline Date Picker
链接: https://github.com/DylanVann/DatePickerCell
供参考: iOS 7 - How to display a date picker in place in a table view?
答案 1 :(得分:0)
最后我得到了解决方案。此代码在设备中正常工作...感谢您的帮助
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
CGRect pickerFrame = datePicker.frame;
pickerFrame.size.height = datePicker.frame.size.height - 50;
datePicker.frame = pickerFrame;
[datePicker setDatePickerMode:UIDatePickerModeDate];
[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];