UIAlertController 显示延迟 [英] UIAlertController showing with delay
问题描述
我的应用程序上的 UIAlertController 出现问题,现在已迁移到带有日期选择器的 iOS8.
I'm experiencing a problem with UIAlertController on my app now migrated to iOS8 with Date Picker inside.
下面是代码.
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];
UIAlertController 和 Date Picker 在用户从 UITableViewController 中选择一行时显示.
UIAlertController and Date Picker is shown when the user select a row from UITableViewController.
问题如下:用户第一次选择行时一切正常……但是如果用户选择取消"然后再次选择细节,UIAlertController 需要 2-3 秒才能显示……这也会发生在模拟器中……
The problem is the following: first time the users select the row everything works fine...but if the user select "Cancel" and then select de tate again the UIAlertController takes 2-3 seconds to show up...this happens also in the simulator...
我快疯了……这让我的应用用户体验很差.
I'm getting crazy....this makes my app have a bad user experience.
任何帮助将不胜感激谢谢
Any help will be strongly appreciated Thanks
亚历克斯
推荐答案
我遇到了与 UIAlertController 相同的问题,该问题是通过从 UITableView 中选择一行来呈现的.第一次一切正常,然后当用户再次触发警报时,在实际显示警报之前有几秒钟的延迟.
I was having the same issue with a UIAlertController presented by selecting a row from a UITableView. The first time everything worked fine, and then when the user triggered the alert again there was a few seconds delay before the alert was actually presented.
作为一种解决方法,我使用了 GCD:
As a workaround I used GCD:
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:AlertView animated:YES completion:nil];
});
这可能是一个错误,因为 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
已经在主线程上执行了.
It is probably a bug since -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
is already executed on the main thread.
我向 Apple 提交了错误报告:rdar://19285091
I submitted a bug report to Apple: rdar://19285091
这篇关于UIAlertController 显示延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!