我有一个 View Controller ,它是从选择表行时执行的segue 加载的。该 View Controller 嵌入在导航 Controller (和选项卡栏 Controller )中。
我通过设置一个新的导航 Controller 并获取它的 subview Controller ,然后将变量传递给特定的 subview 来为该segue做好准备。
当我选择一行时,应用程序有时会挂起(大约 4-5 秒),有时会立即启动。我注意到,当它挂起时,如果我触摸屏幕,下一个 View 将立即加载。
我陷入了什么困境?
编辑,添加代码:
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
}
}
最佳答案
我能够通过将 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
}
})
关于ios - UIViewController 在触摸之前加载缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27597431/