Add Delay to PresentViewController

428 Views Asked by At

I was wondering how to add a 1.0 second delay to this segue I have in my code:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[self presentViewController:homeViewController animated:YES completion:nil];

I know you can do this:

[self performSelector:@selector(showModalTwo:)withObject:someNumber afterDelay:1.0f];

I just dont have this or want to make a function to segue. Any help at all would be great. Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

It is not recommended to add delay for waiting an operation to be done (i.e. the login), instead you can use Grand Central Dispatch

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
        //Background Thread
        // do you login logic here

        dispatch_async(dispatch_get_main_queue(), ^(void){
            //Main Thread : UI Updates
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
            [self presentViewController:homeViewController animated:YES completion:nil];

        });
    });