0

i create an iPad app where i have three custom UIViewController. VC1, VC2, VC3. Its like a hierarchy so you have to step through each stage after another.

Therefore you can´t jump directly from VC1 to VC3.

But if you are in VC3 you can go back to VC2 or VC1 directly. On VC3 i can just call dismissViewControllerAnimated to present the VC2 - cool.

But whats the best way if i would like to jump back from VC3 to VC1 ? Is there a reason why it would be bad to just use "alloc and init" to the VC1 and then presentViewController:animated:completion ?

geforce
  • 2,593
  • 3
  • 28
  • 44

2 Answers2

1

Yes it would be bad since VC1 already exists, you would have a duplicate. You can use this to go from VC3 to VC1.

[self.presentingViewController.presentedViewController dismissModalViewControllerAnimated:YES];
Bob de Graaf
  • 2,630
  • 1
  • 25
  • 43
  • Thx for your help. Unfortunately that doesn´t help. If i log the "self.presentedViewController" or "self.parentViewController" property, i get null. Why? – geforce Feb 16 '12 at 14:25
  • Dismissing from VC3 to VC1 now works. But not like you said with "[self.presentedViewController.presentedViewController dismissModalViewControllerAnimated:YES];". It works when i use: "[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];"... Thanks! My problem above just exists. Should i make a new thread for that? – geforce Feb 17 '12 at 09:50
  • hi no my code was wrong, sorry for that, I'll edit it :) don't worry about making a new thread, that's not necessary. If this code worked, could you mark this answer as accepted so people visiting this thread find the right code? – Bob de Graaf Feb 22 '12 at 15:52
0

Yes it would be very bad to alloc init another VC1.

Just make VC1 delegate of your VC3.

When you want to dismiss VC1 and VC2 from VC3 just call a delegate method like "DismissAllVC" In VC1 into the DismissAllVC method just call

- (void)dismissModalViewControllerAnimated:(BOOL)animated

This will dismiss VC2 and VC3 because they are childs of VC1.

This is what i'll do cause the parent view controller should always be responsible of the childs dismiss.

hope that will help ;)

Iman Zarrabian
  • 230
  • 2
  • 10