iOS segue freeze for many seconds before showing new view

前端 未结 4 562
甜味超标
甜味超标 2020-12-30 05:26

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 pr

4条回答
  •  无人及你
    2020-12-30 05:43

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

    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
    
            }
        })
    
    }
    

    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.

提交回复
热议问题