View Controller 不会立即显示

View Controller doesn't get presented immediately

在我的社交应用程序中,我有 "Home" 屏幕,其中有一个 tableView,最多包含 3 个不同的单元格!然后我实现 didSelect 数据源方法,我在其中执行一些比较以确定我刚刚 selected 的单元格类型......(每次 3 或 4 次比较)对于我 select 的每个单元格,一个新视图控制器被实例化。一个用于照片演示,另一个用于自定义相机演示,最后一个用于另一个简单的视图控制器演示...

问题是,由于无法解释的原因,如果我按下 iPhone 主页按钮,然后再次打开我的应用程序并转到 select 其中一个单元格,最多需要 7 秒直到它呈现视图控制器!然后,如果我关闭该视图控制器,返回 "Home" 和 select 另一个单元格,一切正常!

有人知道会发生什么吗?

编辑:

if currentArea != "Somewhere" {
        if gettingContent == false && objectsArray.count == 0 {
            if firstOfLocalLeaderboard != nil {
                if indexPath.row == 0 {
                    let vc = self.storyboard!.instantiateViewController(withIdentifier: "TopTenAreaController") as! TopTenAreaController
                    vc.area = currentArea

                    let navVC = UINavigationController()
                    navVC.viewControllers = [vc]

                    self.present(navVC, animated: true, completion: nil)
                }
                else if indexPath.row == 1 {
                    if localLeaderboard.count > 0 {
                        let vc = self.storyboard?.instantiateViewController(withIdentifier: "PhotoViewController") as! PhotoViewController

                        vc.objectsArray = localLeaderboard
                        vc.currentArea = currentArea

                        let navVC = UINavigationController()
                        navVC.viewControllers = [vc]

                        self.present(navVC, animated: true, completion: nil)
                    }
                    else {
                        let vc = self.storyboard!.instantiateViewController(withIdentifier: "CameraViewController") as! CameraViewController
                        vc.appearedFromHome = true

                        let navVC = UINavigationController()
                        navVC.viewControllers = [vc]

                        self.present(navVC, animated: true, completion: nil)
                    }
                }
            }
            else {
                if indexPath.row == 0 {
                    if localLeaderboard.count > 0 {
                        let vc = self.storyboard?.instantiateViewController(withIdentifier: "PhotoViewController") as! PhotoViewController

                        vc.objectsArray = localLeaderboard
                        vc.currentArea = currentArea

                        let navVC = UINavigationController()
                        navVC.viewControllers = [vc]

                        self.present(navVC, animated: true, completion: nil)
                    }
                    else {
                        let vc = self.storyboard!.instantiateViewController(withIdentifier: "CameraViewController") as! CameraViewController
                        vc.appearedFromHome = true

                        let navVC = UINavigationController()
                        navVC.viewControllers = [vc]

                        self.present(navVC, animated: true, completion: nil)
                    }
                }
            }
        }

试试这个

DispatchQueue.main.async {
    // present vc
}