我有一个基于标签栏的应用程序。所有 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/