Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

performSegueWithIdentifier tricks to avoid initial delay

Hi there I have a ViewController performing a segue on a button.

- (IBAction)moveToCoolViewButtonTapped {
    [self performSegueWithIdentifier:@"toCoolView" sender:nil];
}

This works fine, apart from an annoying delay the first time it's performed, I guess due to the view not being initialized yet. I obviously don't want to have to prematurely create a lot of views. (There are several others segues planned from the same viewController). So, a long shot perhaps: but I wondered if anyone had any brilliantly inspired tricks to avoid the initial lag?

like image 909
T. Benjamin Larsen Avatar asked Jan 22 '13 12:01

T. Benjamin Larsen


1 Answers

try replace this

[self performSegueWithIdentifier:@"toCoolView" sender:nil];

with this

dispatch_async(dispatch_get_main_queue(),^{
    [self performSegueWithIdentifier:@"toCoolView" sender:nil];
});
like image 65
Tùng Đỗ Avatar answered Sep 30 '22 14:09

Tùng Đỗ