Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing a navigation controller after a modal view controller is presented

I have a tab view controller which has a button like so and when it gets pressed a modal appears:

PostViewController *post = [[PostViewController alloc] init];

// [self.navigationController pushViewController:post animated:YES];

// Presentation
[self presentViewController:post animated:YES completion:nil];

When the modal is done I want to dismiss it and push a new view controller like so:

ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[self.navigationController pushViewController:profile animated:YES];

But I can't do it in the post vc as its a modal. How do I do this?

like image 771
cdub Avatar asked Oct 09 '14 08:10

cdub


2 Answers

You can try using completionBlock.

CompletionBlock is called when presentViewController is done.

PostViewController *post = [[PostViewController alloc] init];
[con presentViewController:post animated:YES completion:^{
    ProfilesViewController *profile = [[ProfilesViewController alloc] init];
    [self.navigationController pushViewController:profile animated:YES];
}];

More information about presentViewController:animated:completion: Apple Doc

completion : The block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.

like image 56
Kevin Machado Avatar answered Nov 15 '22 06:11

Kevin Machado


Dose your tab view controller embedded in a UINavigationController? If you have not, you of course cannot use self.navigationController.

like image 22
Steve Lai Avatar answered Nov 15 '22 04:11

Steve Lai