Reputation: 27
I have what I think is a simple problem. I have three views in my app, View1, View2, View3. I know how to go from View1 to View2, and from View2 to View3, but how do I go from View3 back to View1?
I am using the following method in the View1ViewController.m to go from View1 to View2:
[self presentModalViewController:view2ViewController animated:YES]
And the same thing to go from View2 to View3.
I am including the View2 view controller in the View1 XIB file, and am including the View3 view controller in the View2 XIB file.
I've found that if I use [self dismissModalViewControllerAnimated:YES]
from View3 I can only go back to View2, whereas I need to go all the way back to View1.
Any help/direction would be greatly appreciated.
Many thanks, -Sd
Upvotes: 0
Views: 213
Reputation: 1891
You might consider using a navigation controller to switch between views. Adding views with the pushViewController method. You could then use the (NSArray *)popToRootViewControllerAnimated:(BOOL)animated method in the UIViewController class. There is also popToViewController:animated: that will allow you to pop to a specific viewController.
If you are set on using modal views you can implement a protocol in view3 that view2 implements. When you are ready to pop to view1 from view3 you can call [self dismissModalViewControllerAnimated: YES]; then use your protocol to notify view2 that it should also dismiss its modal view.
Hope this helps.
Upvotes: 1
Reputation: 15597
Don't think of calling -presentModalViewController:
as a way of going from one view controller to another; think of it as a way of, well, presenting a view controller modally. If you want to implement navigation, you should take a look at UINavigationController
.
Upvotes: 2
Reputation: 22403
From your description, it sounds like you're using modal views incorrectly. They are not a way to transition between views, they are a way to briefly show some dialog that will be dismissed soon after (like selecting a date or something). Are you sure that both your views are actually modal views, and not completely distinct?
Upvotes: 1