ios - UIViewController 在触摸之前加载缓慢

标签 ios swift uiviewcontroller ios6 uinavigationcontroller

我有一个 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/

相关文章:

ios - 在 iTunesConnect 上用新的应用程序替换已经接受的应用程序构建

ios - -[AXSpeechAction 保留] : message sent to deallocated instance 0x1c37e2b0

xcode - 使用 Swift 通过 iPhone 扬声器强制播放音频文件

objective-c - 当键盘出现在 iOS 中时,将 UIView 上移

ios - 从远程通知启动时如何使用导航堆栈呈现适当的 View Controller

ios - GPUImageFilterGroup 正在返回黑色图像

ios - 更新后错误 : . ..异常 'NSGenericException' ,原因: 'This coder requires that replaced objects be returned from initWithCoder:'

iphone - 如何在 iphone 应用程序启动时打开不同的 View Controller ?

ios - UIKeyboardTypeDecimalPad 十进制按钮以半宽为上限

objective-c - 状态栏旋转与 UIWindow 分离