如何将UIDatePicker添加到UIAlertController iOS9中
我尝试将date piker添加到如何将UIDatePicker添加到UIAlertController iOS9中,ios,objective-c,uidatepicker,uialertcontroller,Ios,Objective C,Uidatepicker,Uialertcontroller,我尝试将date piker添加到alertcontroller中,但在大小方面存在一些问题。我不知道如何获得datepiker的高度,或者只知道initUIAlertController和datepiker的高度。 所以我所做的是: UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n" preferredSt
alertcontroller
中,但在大小方面存在一些问题。我不知道如何获得datepiker
的高度,或者只知道init
UIAlertController
和datepiker的高度。
所以我所做的是:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
UIView *viewDatePicker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
[viewDatePicker setBackgroundColor:[UIColor clearColor]];
CGRect pickerFrame = CGRectMake(0, 0, self.view.frame.size.width, 200);
UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[picker setDatePickerMode:UIDatePickerModeTime];
[viewDatePicker addSubview:picker];
[alertController.view addSubview:viewDatePicker];
NSDateFormatter *formate=[[NSDateFormatter alloc]init];
[formate setDateFormat:@"hh:mm a "];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
sinceDateString = [formate stringFromDate:picker.date];
[sinceDateButton setTitle:sinceDateString forState:UIControlStateNormal];
}];
[alertController addAction:defaultAction];
[self presentViewController:alertController animated:YES completion:nil];
我发现这个解决方案也是一个同样的问题
*alertController=[UIAlertController alertControllerWithTitle:nil消息:@“\n\n\n\n\n\n\n\n\n”
首选样式:UIAlertControllerStyleActionSheet]
但我知道这是错误的解决方案,因为我看到了灰线。
为什么没有选择
UIDatePicker
作为您的概念,请参见此
\n是新行字符,它将位置移动到下一行的开始处
中间的第二个问题显示了灰线,这意味着你选择了日期选择器
在代码中,您使用了\n\n\n\n\n\n\n10次,删除两次
\n\n然后显示完美
我得到的结果是
为什么没有选择
UIDatePicker
作为您的概念,请参见此
\n是新行字符,它将位置移动到下一行的开始处
中间的第二个问题显示了灰线,这意味着你选择了日期选择器
在代码中,您使用了\n\n\n\n\n\n\n10次,删除两次
\n\n然后显示完美
我得到的结果是
苹果一直不鼓励将UIDatePicker添加到行动表中。从iOS 7开始,苹果就引入了内联日期选择器(参见日历应用程序中的操作)
如果您成功地使用UIAlertController破解了一个解决方案,它可能会在未来的iOS版本中再次崩溃。苹果一直不鼓励将UIDatePicker添加到操作表中。从iOS 7开始,苹果就引入了内联日期选择器(参见日历应用程序中的操作)
如果您使用UIAlertController成功破解了一个解决方案,它可能会在未来的iOS版本中再次中断。这是您当前选定日期的选择行,哦,对不起,我在iOS开发中是新的。但是“\n\n\n”只有一个解决方案添加UIAlertController的高度吗?\n意味着创建新的行确定没有问题,在google中搜索更多您总是可以得到最简单的答案,做得好这是您当前日期的选择行,哦,对不起,我在iOS开发中是新的。但是“\n\n\n”只有一个解决方案添加UIAlertController的高度怎么办?\n意味着创建新的行OK没有问题,在google中搜索更多您总是可以得到最简单的答案,请仔细检查更新答案,但在这里我的建议使用
UIDatePicker
谢谢,这很有帮助!检查更新答案,但在这里我的建议使用UIDatePicker
谢谢你,这很有帮助!
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
UIView *viewDatePicker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,200)];
[viewDatePicker setBackgroundColor:[UIColor clearColor]];
CGRect pickerFrame = CGRectMake(0, 0, self.view.frame.size.width, 200);
UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[picker setDatePickerMode:UIDatePickerModeTime];
[viewDatePicker addSubview:picker];
[alertController.view addSubview:viewDatePicker];
NSDateFormatter *formate=[[NSDateFormatter alloc]init];
[formate setDateFormat:@"hh:mm a"];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
// sinceDateString = [formate stringFromDate:picker.date];
// [sinceDateButton setTitle:sinceDateString forState:UIControlStateNormal];
}];
[alertController addAction:defaultAction];
[self presentViewController:alertController animated:YES completion:nil];