views:

41

answers:

3

Hi,
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 of UINavigationController. 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 !!!

A: 

For the [self.navigationController popToRootViewControllerAnimated:NO]; function to work, you need to add a UINavigationController in your code. Did you do it?

Niko
A: 

No, in fact certainly it is the problem. But i'm watching the documentation, but for this part i can understand what is the principle of UINavigationController, but i can't understand exactly how to use it... i continue my search ! Thank you

Marco
Don't write an answer to your question to add more information on Stack Overflow. Instead, edit your original question, or add a comment.
Shaggy Frog
A: 

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. ;-)

Niko
Don't post multiple answers. Instead, edit your original answer to add more detail.
Shaggy Frog
Sorry about that. I'll do that next time ;-)
Niko