【问题标题】:UIAlertController showing with delayUIAlertController 延迟显示
【发布时间】:2014-12-14 11:53:20
【问题描述】:

我的应用程序上的 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 秒才能显示出来...这也发生在模拟器中...

我快疯了……这让我的应用程序的用户体验很差。

任何帮助将不胜感激 谢谢

亚历克斯

【问题讨论】:

  • 尝试将self替换为AlertViewbringSubviewToFront并在self上调用dismissViewControllerAnimated:completion:
  • 用 AlertView 口语变化替换自我。
  • 如果我调用“dismissViewControllerAnimated:completion: on self”我得到一个错误...不确定我是否正确编码...你能发布一个示例代码吗?

标签: objective-c xcode swift uialertview uialertcontroller


【解决方案1】:

我在通过从 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

【讨论】:

  • 试过这个,似乎没有解决我的问题。仍然需要 3 秒才能显示警报。
  • 我在表格视图中看到了完全相同的问题。谢谢,您的解决方案对我有用。
  • 仍然延迟
  • 这里也一样,点击表格视图单元格时会发出警报...没有完全解决问题,但让它变得更好
  • 我也遇到这个问题,还没解决
【解决方案2】:
    DispatchQueue.main.async {
        self.present(alertView, animated: true, completion:nil)
    }

Swift 3.0 版本。或者,设置动画:假也解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多