0

I have a modal view controller that was presented like so:

[self presentViewController:photo animated:YES completion:nil];

Thus photo is a modal view controller, but when its done I want to push to a navigation view controller like so:

[self dismissViewControllerAnimated:NO completion:^{

    // UINavigationController *nav = [[UINavigationController alloc] init];
    //nav.delegate = self;

    ProfilesViewController *profile = [[ProfilesViewController alloc] init];
    [_nav pushViewController:profile animated:YES];
}];

nav is a property in the photo's view controller that also has delegation. Still isn't working so what am I missing?

cdub
  • 24,555
  • 57
  • 174
  • 303
  • Wait! Don't forget about **transitionFromViewController:toViewController:duration:options:animations:completion:** which MAY be what you are after. – Fattie Oct 12 '14 at 12:02

1 Answers1

0

Don't complex the thing while it can be done very easily,

In view controller where you're presenting the photo modal view controller, present it with a notification like this,

[self presentViewController:photo animated:YES completion:^{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToNextView:) name:@"someNotification" object:nil];
}];

And dismiss your photo modal view controller with call to that notification like this,

[self dismissViewControllerAnimated:YES completion:^{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"someNotification" object:nil];
}];

And now you can push to another view controller like this,

- (void) pushToNextView:(NSNotification *)notification {
    //If you want some value from your notification
    //NSDictionary *someValue = notification.object;
    [self.navigationController pushViewController:ProfilesViewController animated:YES];
}
Hemang
  • 26,840
  • 19
  • 119
  • 186
  • okay so instead of object:nil I can do object:@"value" and then grab that value in notification.object? – cdub Oct 12 '14 at 08:49
  • Yes, you can. Even you can pass multiple values inside a `NSDictionary` too. – Hemang Oct 12 '14 at 08:50
  • One issue is it still goes back to the main view controller before the push. I have seen apps not have this. – cdub Oct 12 '14 at 09:05
  • @chris, Yes that's right. It should go. But if you really don't want to show `main view controller` just set `animated:NO` while `presenting` and `dismissing` the photo model view controller. This will not give you animation for the same but *may be* not show you `main view controller`. – Hemang Oct 12 '14 at 09:10
  • the whisper app found a way to do it with animated = yes – cdub Oct 12 '14 at 09:13
  • thats how i want it, to dismiss modal is to go back to where you came and to push new photo to picture vc with navigation bar present. both should be animated – cdub Oct 12 '14 at 09:14
  • Whisper app developers may applied some present/dismiss/push animation with the same flow. – Hemang Oct 12 '14 at 09:25
  • PS guys don't forget if you fool with NSNotificationCenter, it is absolutely essential to http://stackoverflow.com/questions/15656367/is-nsnotificationcenter-removeobserver-in-arc-needed – Fattie Oct 12 '14 at 11:07
  • hi @cdub - did you ever resolve this? you should tick and answer, dude – Fattie Mar 31 '16 at 15:08