本文介绍了使用 instantiateViewControllerWithIdentifier 但没有 performSegueWithIdentifier 时延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

下面的代码用于将另一个视图控制器推送到导航堆栈.

The code below is used to push another view controller onto the navigation stack.

当使用 instantiateViewControllerWithIdentifier 时,segue 第一次明显迟缓(约 3 秒),但随后每次都发生得相当快.其他 SO 帖子建议确保 segue 发生在代码完成的主线程上,但这并没有解决问题.

When using instantiateViewControllerWithIdentifier, the segue is noticeably sluggish the first time (~3 seconds) but occurs reasonably fast each subsequent time. Other SO posts suggested ensuring the segue occurs on the main thread, which the code accomplishes, but this didn't fix the problem.

但是,使用 performSegueWithIdentifier 不会导致延迟.

However, using performSegueWithIdentifier causes no delay.

SendViewControllerviewDidLoad 代码对于第一次和后续推送是相同的.

The viewDidLoad code for SendViewController is the same for the first and subsequent pushes.

尝试为目标视图控制器清空 viewDidLoad,但对于 instantiateViewControllerWithIdentifier 仍然存在延迟,但对于 performSegueWithIdentifier 不存在延迟.

Tried blanking out viewDidLoad for the destination view controller, but still the lag exists for instantiateViewControllerWithIdentifier but not for performSegueWithIdentifier.

如何使用 instantiateViewControllerWithIdentifier 解决延迟问题?

How to fix the delay with instantiateViewControllerWithIdentifier?

没有延迟:

@IBAction func buttonTapped(sender: UIButton) {
    performSegueWithIdentifier(SendSegue, sender: self)
}

第一次显示 SendViewController 时导致延迟:

Results in delay when showing SendViewController for first time:

@IBAction func buttonTapped(sender: UIButton) {
    dispatch_async(dispatch_get_main_queue()) {
        let vc = self.storyboard!.instantiateViewControllerWithIdentifier(self.SendViewControllerID) as! SendViewController
        self.navigationController!.pushViewController(vc, animated: true)
    }
}

推荐答案

问题被隔离到目标视图控制器中存在 UITextField,也就是说,删除 UITextField 会消除滞后.

The problem was isolated to the presence of a UITextField in the destination view controller, that is, removing the UITextField removes the lag.

然后它被进一步隔离为自定义字体的存在.

Then it was further isolated to the presence of a custom font.

换句话说,在 UITextField 上使用系统字体而不是自定义字体可以消除滞后.没有解释为什么,但它有效.

In other words, using the system font on the UITextField, rather than a custom font, removes the lag. No explanation why, but it works.

这篇关于使用 instantiateViewControllerWithIdentifier 但没有 performSegueWithIdentifier 时延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:33