在显示新视图之前,iOS segue冻结了几秒钟 [英] iOS segue freeze for many seconds before showing new view

查看:88
本文介绍了在显示新视图之前,iOS segue冻结了几秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的主视图中,我有一个表视图和两个原型单元格。我使用故事板为每个单元配置了segue。在视图控制器中,我覆盖prepareForSegue以将所选单元格上的信息传递到目标视图。

In the main view of my app I have a table view and two prototype cells. I have configured the segues for each cell using the storyboard. In the view controller I override prepareForSegue to pass information on the selected cell to the destination view.

目标视图不是特别复杂,当然也不需要任何重量处理加载。

The destination view isn't particularly complex and certainly doesn't require any heavy processing to load.

问题

当我点击一个单元格时主控制器第一次,目标视图在长时间延迟后出现,从5到40秒。

When I tap on a cell in the main controller for the very first time, the destination view appears after a long delay, from 5 to 40 seconds.

编辑#2 :后续点击通常更快

请注意:


  • 如果我点击相同的单元格再次出现目标视图之前,这会触发目标视图立即显示。

  • 如上所述,但点击不同的单元格会导致视图立即出现但是来自第一个单元格的数据。

  • 如上所述,但是点击不同的控件(没有关联的segues)会触发目标视图显示为immed ivert。

  • 随后的点击通常表现出较少的延迟。

  • Time Profiler - 我能看到的 - 表明在此期间绝对没有发生任何事情。那几秒钟的延迟。

  • 我尝试了不同类型的segue,但没有区别

  • 一些println表明发生以下事件序列:

  • If I tap on the same cell again before the destination view has appeared, this triggers the destination view to appear immediately.
  • As above, but tapping on a different cell results in the view appearing immediately but with the data from the first cell.
  • As above, but tapping on a different control (with no associated segues) triggers the destination view to appear immediately.
  • Subsequent "taps" generally manifest less delay.
  • The Time Profiler - for what I can see - shows that absolutely nothing is happening during those many seconds of delay.
  • I have tried different type of segues, but it made no difference
  • A few println's show that the following sequence of events occurs:


  • 在主视图中,执行prepareForSegue(无延迟)

  • 然后执行目标viewDidLoad(没有延迟)

  • ...长时间延迟...

  • 集合目标控制器中的表视图和表视图开始调用与控制器相关的数据源相关方法。

  • 视图最终出现(带有不需要的动画,BTW,但这是一个不同的问题)

  • in the main view, prepareForSegue is executed (no delays)
  • then the destination viewDidLoad is executed (no delays)
  • ... long delay ...
  • the collection and table views in the destination controller start invoking the data source related methods to fetch the data from the controller.
  • the view finally appears (with an unwanted animation, BTW, but that's a different problem)

根据我对此主题的看法,我怀疑问题是可能与上述一些歌剧有关tions发生在后台主题中。

From what I have read on this topic, I suspect the problem is potentially related to some of the above operations happening in a background thread.

知道我可能做错了什么吗?

Any idea what I might be doing wrong?

编辑#1 :添加了一些代码

在主视图控制器中,segue已使用故事板进行链接(CTRL-将两个原型单元拖到目标中查看)。

In the main view controller the segues have been link using the story board (CTRL-drag the two prototype cells into the destination view).

代码看起来有点如下:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
    var assetIndex = assetsTable.indexPathForSelectedRow()?.row

    println("prepare for segue - start: \(assets[assetIds[assetIndex!]]!.Name)")

    if let destination = segue.destinationViewController as? AssetThingsListViewController
    {
        destination.bundlesRepository = bundlesRepository!
        destination.asset = assets[assetIds[assetIndex!]]
    }

    println("prepare for segue - end")
}

编辑#3 我在BitBucket

推荐答案

我检查了你的项目。虽然我也找不到其他任何东西,但我也怀疑它是线程问题。

I checked your project. And while I also couldn't find anything else, I also suspect that it's a problem with threading.

我设法通过为<$实现委托来解决问题c $ c> tableview 并在代码中显示新控制器:

I managed to fix the problem by implementing a delegate for the tableview and present the new controller in code:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let destination = storyboard?.instantiateViewControllerWithIdentifier("BuilderToysListViewController") as! BuilderToysListViewController
    destination.botsRepository = botsRepository!
    destination.builder = builders[builderIds[indexPath.row]]

    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        self.presentViewController(destination, animated: true) { () -> Void in

        }
    })

}

请注意,您已设置视图控制器故事板ID: BuilderToysListViewController 并设置tableview委托。不要忘记删除segues。

Notice you have the set the view controller storyboard id: BuilderToysListViewController and also set the tableview delegate. Don't forget to remove the segues.

最后在新视图控制器中解除视图使用此代码:

At the end to dissmis the view in the new view controller use this code:

@IBAction func backButton(sender: AnyObject)
{
    dismissViewControllerAnimated(true, completion: { () -> Void in

    })
//        performSegueWithIdentifier("segueToysByBuilder", sender: nil)        

}

这将允许您正确关闭视图而不是错误地创建新视图。

This would allow you to properly close the view instead of wrongly creating a new one.

这篇关于在显示新视图之前,iOS segue冻结了几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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