UIViewController加载缓慢,直到触摸

时间:2014-12-22 06:17:09

标签: ios swift uiviewcontroller ios6 uinavigationcontroller

我有一个视图控制器,它是从选择了表格行时执行的segue加载的。该视图控制器嵌入在导航控制器(和标签栏控制器)中。

我通过设置一个新的导航控制器并获取它的子视图控制器,然后将变量传递给特定的子项来准备该segue。

当我选择一行时,应用程序会挂起(大约4-5秒),有时会立即触发。我已经注意到,当我触摸屏幕时它会挂起,下一个视图会立即加载。

我被抓住了什么?

编辑,添加代码:

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

    selectedId = myArray.objectAtIndex(indexPath.row).valueForKey("myId") as Int
    performSegueWithIdentifier("goToExtraDetails", sender: self)

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "goToExtraDetails" {

        let nextNavVc = segue.destinationViewController as ExtraMenuNavigationViewController

        let nextChildVc = nextNavVc.childViewControllers[0] as ExtraMenuViewController

        nextChildVc.thisId = selectedId

    }
}

1 个答案:

答案 0 :(得分:2)

我能够通过将if语句放入主线程

的调度中来消除延迟
dispatch_async(dispatch_get_main_queue(), {
    if segue.identifier == "goToExtraDetails" {

        let nextNavVc = segue.destinationViewController as ExtraMenuNavigationViewController

        let nextChildVc = nextNavVc.childViewControllers[0] as ExtraMenuViewController

        nextChildVc.thisId = selectedId

    }
})