我的应用程序上的 UIAlertController 出现问题,现在我的应用程序已迁移到带有日期选择器的 iOS8。
下面是代码。
UIAlertController *AlertView = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
[AlertView dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *set = [UIAlertAction actionWithTitle:NSLocalizedString(@"Set to today", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
[self set_to_today:nil];
[AlertView dismissViewControllerAnimated:YES completion:nil];
[self.tableView reloadData];
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
[AlertView dismissViewControllerAnimated:YES completion:nil];
}];
UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker setDate:data_appo];
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[AlertView.view addSubview:datePicker];
[AlertView addAction:ok];
[AlertView addAction:set];
[AlertView addAction:cancel];
[self.view bringSubviewToFront:datePicker];
[self presentViewController:AlertView animated:YES completion:nil];
当用户从 UITableViewController 中选择一行时,会显示 UIAlertController 和 Date Picker。
问题如下: 用户第一次选择行时一切正常...但是如果用户选择“取消”然后再次选择 de tate UIAlertController 需要 2-3 秒才能显示出来...这也发生在模拟器中...
我快疯了……这让我的应用程序的用户体验很差。
任何帮助将不胜感激 谢谢
亚历克斯
最佳答案
我在通过从 UITableView 中选择一行来呈现 UIAlertController 时遇到了同样的问题。第一次一切正常,然后当用户再次触发警报时,在实际显示警报之前有几秒钟的延迟。
作为一种解决方法,我使用了 GCD:
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:AlertView animated:YES completion:nil];
});
这可能是一个错误,因为 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
已经在主线程上执行。
我向 Apple 提交了错误报告:rdar://19285091
https://stackoverflow.com/questions/26449724/