UIAlertController显示延迟

use*_*643 39 xcode objective-c uialertview swift uialertcontroller

我在我的应用程序上遇到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];
Run Code Online (Sandbox Code Playgroud)

当用户从UITableViewController中选择一行时,将显示UIAlertController和Date Picker.

问题如下:第一次用户选择行一切正常...但如果用户选择"取消",然后再次选择de tate,UIAlertController需要2-3秒才能显示...这也发生在模拟器......

我疯了......这使我的应用程序有一个糟糕的用户体验.

任何帮助将非常感谢谢谢

亚历克斯

Tom*_*usm 90

通过从UITableView中选择一行,我遇到了与UIAlertController相同的问题.第一次一切正常,然后当用户再次触发警报时,在实际发出警报之前有几秒钟的延迟.

作为一种解决方法,我使用GCD:

    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:AlertView animated:YES completion:nil];
    });
Run Code Online (Sandbox Code Playgroud)

这可能是一个错误,因为-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath已经在主线程上执行了.

我向Apple提交了一份错误报告:rdar:// 19285091

  • 我在桌面视图中看到完全相同的问题.谢谢,您的解决方案对我有用. (6认同)
  • 试过这个,似乎没有解决我的问题.仍需要3秒钟才能显示警报. (5认同)

Mik*_*sya 25

    DispatchQueue.main.async {
        self.present(alertView, animated: true, completion:nil)
    }
Run Code Online (Sandbox Code Playgroud)

Swift 3.0版.或者,设置animated:false也解决了我的问题.