Spenciefy Spenciefy - 6 months ago 61
iOS Question

Dismiss modal, then immediately push view controller

How can I dismiss a modal and then immediately push another view?

I am adding this code in a didSelectRowAtIndexPath:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ChatTableViewController *chatVC = (ChatTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"chatVC"];
[self dismissViewControllerAnimated:YES completion:^{
[[self navigationController] pushViewController:chatVC animated:YES];

The modal view dismisses, but nothing happens after. Any ideas?


You can't push a view controller into a view dismissed, if it's dismissed it disappears so it's not logical to push another view, cause the parent view controller is deleted. Probably you have this: - ViewController 1 --> Modal ViewController 2 -->Wanted to dismiss VC2 and push VC3

What you have to do is - ViewController 1 --> Modal ViewController 2 --> Dismiss VC2 --> Push VC3 on VC1

You can do it with notifications. The most efficient way is to use delegates, create a delegate on VC2 that notifies V1 when it dismisses and then just push VC3.