ios - 呈现模态视图 Controller 的延迟

标签 ios objective-c iphone modalviewcontroller

我有一个基于标签栏的应用程序。所有 5 个选项卡中都有导航 Controller ,其中自定义 View Controller 的实例正确设置为 Root View Controller 。这加载就好了。其中一些 View Controller 包含 TableView 。当用户在表格 View 中选择一行时,我想向用户显示一个模态视图 Controller 。 didSelectRowAtIndexPath 委托(delegate)方法的(相关部分)如下所示:

SampleSelectorViewController *sampleVC = [[SampleSelectorViewController alloc] init];
[self presentViewController:sampleVC animated:YES completion:NULL];

模态视图 Controller 出现了,但它出现在一个非常明显的延迟之后。有时它甚至需要用户再次点击该行。我已经验证的几件事是:

  • 当用户点击行时,会调用表格 View 的 didSelectRowAtIndexPath 方法
  • didSelectRowAtIndexPath 方法不包含任何阻塞调用。没有执行网络操作,模态视图 Controller 的设置不涉及任何处理密集型任务。它显示的数据是静态的。
  • 如果我将新的 View Controller 推送到导航堆栈上(其他一切都保持不变),它会完美运行而不会出现任何延迟。只有在模态呈现时才会遇到延迟。

有什么想法/建议吗?

最佳答案

似乎从 tableView:didSelectRowAtIndexPath: 中调用 presentViewController:animated:completion 是有问题的。在 Instruments 中使用 Time Profiler 时,也很难找到任何突出的东西。有时我的模态视图会在不到一秒的时间内出现,而其他时候则需要 4 秒甚至 9 秒。

我认为它与底层 UIPresentationController 和布局有关,这是我在点击一行和在 Time Profiler 中看到模态演示之间选择时间区域时看到的少数几件事之一.

存在描述此问题的雷达:http://openradar.appspot.com/19563577

解决方法很简单但并不令人满意:稍微延迟演示文稿以避免任何有争议的行为导致速度减慢。

dispatch_async(dispatch_get_main_queue(), ^{
   [self presentViewController:nav animated:YES completion:nil];
});

关于ios - 呈现模态视图 Controller 的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26469268/

相关文章:

iphone - 是否可以将 UIView 及其 subview 绘制到图形上下文中?

objective-c - AFNetworking - 向 REST 服务发出 XML POST 请求?如何形成NSDictionary参数?

ios - 静态库 - 复制文件目标

ios - iPhone 6 plus 的@3x Assets 可以有奇数像素吗?即 248 x 171 像素

iOS - 无法使用 Twitter/Fabric New SDK 上传媒体

iphone - 在 iOS 中与 Instagram 上的图像共享文本

ios - PushViewController 导致黑屏,没有 Storyboard

ios - 更改 collectionView 单元格中项目的颜色和文本

ios - 添加到收藏夹功能[swift]

objective-c - 循环在 Interface Builder 中设置的布局