i've a 3 views based app. To navigate from different views i use the delegate method, for example in the second view i've a delegate which is the reference to the first view and when i want to pass from the second to the first view, i call a method of the delegate which made a simple : [self dismissModalViewControllerAnimated:YES];
.
Now the problem is that i need to do this thing:
1 ---> 2 ---> 3 ---> 1 . So i want to return to 开发者_开发知识库the first view from the third. Using the dismissModalViewControllerAnimated i can see just a moment that i transit through the second view and then i reach the first. If it's possible, i want to avoid this thing. I found something about the possibility to use the [self.navigationController popToRootViewControllerAnimated:NO];
, i tried to use it instead of dismissModalViewControllerAnimated but the program did anything.
Update
Problem solved, every problem was caused by the incorrect initialization ofUINavigationController
. I find a solution to init it correctly inside my AppDelegate file:
UINavigationController* controller=[[UINavigationController alloc] initWithRootViewController:viewController];
controller.navigationBarHidden=TRUE;
[window addSubview:controller.view];
[window makeKeyAndVisible];
Now everything works fine, the only thing which leaves me perplexed is that i can't release my controller
instance otherwise the views will not diplay.
Thank you to all !!!
For the [self.navigationController popToRootViewControllerAnimated:NO];
function to work, you need to add a UINavigationController
in your code. Did you do it?
If you want, you have the possibility to create an Xcode project Navigation-based. It can help you. Once done. To implement your views architecture, here is how you can do.
In View1Controller.m
- (IBAction)goToView2
{
View2Controller *view2 = [[View2Controller alloc] init];
[self.navigationController pushViewController:view2 animated:YES];
[view2 release];
}
In View2Controller.m
- (IBAction)goToView3
{
View3Controller *view3 = [[View3Controller alloc] init];
[self.navigationController pushViewController:view3 animated:YES];
[view3 release];
}
In View3Controller.m
- (IBAction)goToView1
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Note that, UINavigationController automatically create a back button, when invoking pushViewController
. You have the possibility to hide it by adding :
self.navigationItem.hidesBackButton = YES;
in the view controller invoked by pushViewController
.
If you still have troubles implementing NavigationController, do not hesitate to ask. ;-)
精彩评论