操作表内的 UIDatePicker 不工作
UIDatePicker inside actionsheet is not working
我试图在操作中显示 UIDatePicker sheet 但它不起作用。
这是我的代码。点击按钮我写了这段代码
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 内联日期选择器代码
Link : https://github.com/DylanVann/DatePickerCell
供参考: iOS 7 - How to display a date picker in place in a table view?
终于找到解决办法了。此代码在设备中运行良好...感谢您的帮助
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];
我试图在操作中显示 UIDatePicker sheet 但它不起作用。
这是我的代码。点击按钮我写了这段代码
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 内联日期选择器代码
Link : https://github.com/DylanVann/DatePickerCell
供参考: iOS 7 - How to display a date picker in place in a table view?
终于找到解决办法了。此代码在设备中运行良好...感谢您的帮助
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];