Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pushViewController Extremely slow

What could cause pushViewController to be extremely slow? (it takes 30+seconds for the new view to appear)

Basically, I'm doing something like this:

SecondViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"correctID"];
vc.something = something;
[self.navigationController pushViewController:vc animated:YES];
CLS_LOG(@"Pushed Controller...");

and i'm logging at the beginning of viewdidload inside the second view controller. I'm not subclassing other methods.

Between Pushed Controller... and the next log from viewdidload there's a huge delay.

How would you debug this?

I already tried with the TimeProfiler but apparently it shows nothing.

like image 790
Luca Vitucci Avatar asked Sep 09 '14 22:09

Luca Vitucci


2 Answers

Dino's answer saved my life. He got my upvote. I'm just adding this for modern swift users.

     DispatchQueue.main.async {
          self.navigationController?.pushViewController(vc, animated: true)
     }
like image 75
ScottyBlades Avatar answered Oct 06 '22 10:10

ScottyBlades


Had similar problem before, try the following

dispatch_async(dispatch_get_main_queue(), ^{
    // your navigation controller action goes here
});
like image 44
Dino Tw Avatar answered Oct 06 '22 10:10

Dino Tw