views:

102

answers:

1

Hii...i am new to iPhone programming..can anybody help me out please...!! I have multiple viewControllers..in First ViewController called HomeViewController i called the method [self presentModalViewController:aboutViewController animated:YES]; in a IBAction for aboutButton to move to AboutViewController and in the AboutViewController i called the method [self presentModalViewController:ContactUsViewController animated:YES]; to move to that view controller and one more method [self dismissModalViewControllerAnimated:YES]; to go back to HomeViewController.

in the 3rd, ContactUSViewController i called the method [self dismissModalViewControllerAnimated:YES];to go back to the AboutViewController..and i want to go directly to HomeViewController from here(ContactUsViewController).i used [self presentModalViewController:homeViewController animated:YES]; but its not working...

How to do that...?

Thank u..

+2  A: 

According to the doco for dismissModalViewControllerAnimated:

If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack.

So from your ContactUsViewController you need to call dismissViewControllerAnimated on the HomeViewController. You can access that view controller through parentViewController property. So your code in the dismissAction for the ContactUsViewController is:

- (IBAction)dismissAction:(id)sender
{
    // get your parent (ie AboutViewController)
    UIViewController * parent = self.parentViewController;

    // get its parent (ie HomeViewController)
    [parent.parentViewController dismissModalViewControllerAnimated:YES];
}

There might be a better way of getting to your HomeViewController, but for your shallow stack of view controllers, this should be fine (I tried this out and it worked).

Cannonade
@macharlarakesh If there is something specific about this answer that you need clarifying, leave a comment here.
Cannonade
yes..., its worked Cannonade...!!Thank u very much
rockey
@macharlarakesh Glad to hear it :). You can indicate the answer was helful by clicking the "accept answer" tick right under the vote number on the left hand side.
Cannonade