延迟呈现模态视图控制器 [英] Delay in presenting a modal view controller

查看:102
本文介绍了延迟呈现模态视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a tab bar based app. There are navigation controllers in all 5 tabs with instances of custom view controller setup properly as root view controllers. This loads just fine. A couple of these view controllers contain table views. I want to show a modal view controller to the user when they select a row in the table view. The (relevant part of) didSelectRowAtIndexPath delegate method looks as follows:

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

模态视图控制器出现但是在非常明显的延迟后出现。有时它甚至要求用户第二次点击该行。我已经验证过的一些事情是:

The modal view controller appears BUT it appears after a very noticeable delay. At times it even requires the user to tap the row a second time. A few things that I have already verified are:


  • 当用户点击行时,会调用表视图的didSelectRowAtIndexPath方法

  • didSelectRowAtIndexPath方法不包含任何阻塞调用。没有执行网络操作,模态视图控制器的设置不涉及任何处理密集型任务。它显示的数据是静态的。

  • 如果我将新的视图控制器推到导航堆栈上(其他一切保持完全相同),它的行为完全没有任何延迟。只有在遇到模式时才会遇到延迟。

任何想法/建议?

推荐答案

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

It seems calling presentViewController:animated:completion from within tableView:didSelectRowAtIndexPath: is problematic. It's difficult to find anything that stands out when using the Time Profiler in Instruments, also. Sometimes my modal view comes up in less than a second and other times it takes 4s or even 9s.

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

I think it's related to the underlying UIPresentationController and layout, which is one of the few things I see when selecting the region of time between tapping on a row and seeing the modal presentation in the Time Profiler.

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

A Radar exists describing this issue: http://openradar.appspot.com/19563577

解决方法很简单但不满意:稍微延迟演示文稿以避免引起减速的任何引起争议的行为。

The workaround is simple but unsatisfying: delay the presentation slightly to avoid whatever contentious behavior is causing the slowdown.

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

这篇关于延迟呈现模态视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆