popToRootViewControllerAnimated Question - iphone

I have a UINavigationController in my iPhone app controlling views in a drill-down fashion. I have 4 viewcontrollers that I pass through before I have a "Start over" button, where I would like the action to send the user back to the beginning of the view hierarchy.
[self.navigationController popToRootViewControllerAnimated:YES];
but it looks like it simply brings up a new rootviewcontroller on top of the current view controller.
Is there a way to pop the views back to the very beginning of the navigation drill down?
Any help would be great!
Many thanks,
Brett

Something else is going on here. I use popToRootViewControllerAnimated in on of my apps and it does exactly what you are after.

and if you want to goback direction to your desired view controller then use the code bellow-
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:3] animated:YES];
Here 'objectAtIndex:3' is the flow position(i.e. index) of your viewControllers. For the root it would be 0.

Related

NavigationController Issue on iphone

I am using navigation bar on my application for reach next views in my iphone application.
in a stage of view I want reach back my first view.How can i do it please give me suggestion.Thanks.
There is a popToRootViewControllerAnimated: method that will remove all controllers from the stack and return the user to the first view controller.
See the Apple docs.
[self.navigationController popToRootViewControllerAnimated:YES];
This call will take you to the root of your view controllers
You need to use to go back to your previous view
[self dismissModalViewControllerAnimated:YES];
Hope it helps.

dismissModalViewController multiple

So, I am using a RootViewController from which you can display first ViewController Categories and then from Categories you display next ex. Music
RootViewController -> Categories -> Music
In RootViewController I use this
[self presentModalViewController:categoriesView animated:NO];
to present the modal view and then dismiss it from Categories with
[self dismissModalViewControllerAnimated:NO];
From Categories to Music I use again
[self presentModalViewController:fruitView animated:NO];
to present the Music modal view and then dismiss it in music with again the same as above.
Is there a possibility to dismiss two modal views? I want a method that leads from Music back to RootViewController, dismisses both last modal views.
Any ideas?
Hi Use this Following code[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
Are you sure you want to use modal views for this? It sounds like what you're trying to do is better solved with a UINavigationController, where you can push and pop view controller's in a stack (and there's a popToRootViewControllerAnimated: message you can use).
This is how drill-down navigation is idiomatically handled in iOS (in the iPod, Notes, Contacts, Videos, Photos apps for example).
There's sample code for this in Xcode, I believe.
UINavigationController has a popToRootViewControllerAnimated: method, which per the documentation:
Pops all the view controllers on the
stack except the root view controller
and updates the display.
Use popToRootViewControllerAnimated method of UINavigationController.
[self.navigationController popToRootViewControllerAnimated:YES];
What you're talking about here, going from more general to more specific views, is better handled with a UINavigationController pushing and popping views. These are the views which slide left and right on the screen. Pushing means it slides in from the right (and shows a new, more specific view). Popping slides back to the right and shows a more general view.
A modal view controller is the one that slides in from the bottom of the screen. Look at the iPod app on your device for the way to handle this.
I use a nice utility method to do this... see here:
How to dismiss the two or more dismissModalViewController?
Use This, In music view write this for dissmiss 2 view .
[RootViewController dismissModalViewControllerAnimated:YES];
Here RootViewController is an object of RootViewController
Hope this will help u.

iPhone : how can i move to front page in navigation Controller?

how can I move to front page in navigation Controller?
i know that if i want to move to rootpage, i can use
[self.navigationController popToRootViewControllerAnimated:YES];
but i want to move in front of 2pages. not root page and before page.
how can I do for it?
If you know the viewController on the navigation bar's view controller stack then you can use:
[self.navigationController popToViewController:viewControllerToShow animated:YES];
popToViewController:animated:
Pops
view controllers until the specified
view controller is at the top of the
navigation stack.
Yes you can use
popToViewController:animated:
Pops view controllers until the specified view controller is at the
top of the navigation stack.
In addition to the above answers, if you can't have an instance of the view controller you can do so by the index of the view controller in the stack.
NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:2] animated:YES];
If you hold a reference to the mentioned ViewController*, you can use;
[self.navigationController popToViewController:(UIViewController *) animated:(BOOL)];
This way it goes back till it reaches the given ViewController.
Other workarounds can be, going to root and then navigating to the main page (if it is level 1, of course) without animation. Or you can pop the ViewControllers one by one, till you are there... It all depends on your structure.
Beware though, if you are holding a reference to the mentioned ViewController, you need to retain/release it properly.
I hope it helps

Keep new view in a tab when switching to another tab

This is the situation:
I have a tab bar with 2 tabs. Tab01 and Tab02.
In Tab01 I have a button which pushes repVC:
repVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:repVC animated:YES];
[(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
[repVC release];
Inside repVC I have another button which pushes an MFMailComposerViewController:
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[self presentModalViewController:mail animated:YES];
[mail release];
The problem is: when mailView is shown(in Tab01) and I click Tab02, then back to Tab01, the mailView is hidden and even if I click the email button again, the view won't be presented.
So what I have is: Tab01.view -> repVC.view -> mail.view
For repVC, I use this line when I push the view so that even if I go switch tabs, that view will still be activated:
[(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
But I can't do the same for mail because tabController is declared in another class which I cannot import. So I can't access the tabController and set the view for Tab01.
Hope the edit helped the understanding.
Hmm,
I still would suggest to use a Navigationcontroller. Would make things way easier, is conform to apple guidelines and suggestions and is pretty fast implemented. (Just create a Navigationcontroller, put the View of Tab1 as main view and hand it over to the TabbarController. Then for the mailView use [self.navigationController pushViewController:mail animated:YES]; Then the navcontroller "saves" the present view for you when u switch tabs)
But if for some Reason you have to use a modalViewcontroller you could either just deactivate the tabbar while the ModalView is shown or try to implement a switch or a simple if...else case in your ViewWillAppear where u check what screen to load.
Then Clean out the Window and load the right screen.
Hope you get the idea of what I mean, sometimes my way of writing seems to confuse people. ^^
A little more information would be great.
How did u set up your TabbarController?
How do u push the new view? Within a UINavigationController? If not, then do it with a navController, he should save the actual state of view and your problem should be solved.
If u already use a navController please post your ViewDidLoad and ViewWillAppear of the Viewcontroller of Tab 1
As #Amandir points out you could probably solve your problems by using a UINavigationController. I get a feeling that you are trying to abuse the modal view controller concept a bit and that's why it doesn't work as you expect. When you use presentModalViewController:animated: the intention should be that you are displaying a view that is modal, i.e. the user must interact and dismiss the modal view before she can continue.
What the paragraph above means that when you present a modal view controller it shouldn't be possible to use the tab bar. Since you are using the word push I'm guessing that you would like change the view of Tab01 while still being able to use the functionality of the tab bar. The problem is that there isn't any built-in method of pushing view controllers besides UINavigationController. persentModalViewController:animated: should only be used in case where you want a modal view, which on the iPhone means a full screen view.
The easiest way would probably be to use an UINavigationController and hide the navigation bar. Then you would get the functionality I think you are after. The other option is to manually add and remove sub views.
[self.view addSubview:repVC.view];
and
[repVC.view removeFromSuperview];
[self.view addSubview:mail.view];
You can use block animations if you want some fancy transitions.

iPhone view navigation - any clever ideas?

I have an app that is built starting from a tab bar controller. It's possible for the user to bring up other screens that are loaded with:
[self.navigationController pushViewController:nextSCreen animated:YES];
The user travels several levels deep this way.
Eventually I want to be able to jump back to the original screen. I can't use:
[self.navigationController popViewControllerAnimated:TRUE];
because it only returns me one level. I haven't been able to use
[self.navigationController popToViewController:whereIStarted animated:YES];
because I'm not sure how to get the right value for whereIStarted. Remember this is a specific tab from the tab bar controller.
Does anyone have any suggestions?
Tell me if I'm unclear. Farsi is my first language.
If you're trying to get back to the root controller, you can use:
[self.navigationController popToRootViewControllerAnimated:YES];