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开发者_如何学Go, 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
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
.
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?
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.
精彩评论