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];
Related
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.
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
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.
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.
i'm working on iphone app which will show 4 buttons in first view. on click of a button, it will load a new view with navigation controller. this navigation controller view allows to travel upto 11 sub views. in 11th sub view, i've a reset button. on click of reset button, i've to go back to navigation controllers first view without traversing all the 11 views? is it possible to achieve it? if yes how? if no, what can be the solution?
You can also use the:
[self.navigationController popToRootViewControllerAnimated:YES];
u can use [self.navigationController popToViewController:objFirstViewController animated:YES] in the 11th view when you want to pop directly to the first view.
And if you are sure that you have to move to the first view and it is a rootviewcontroller then you can directly use
[self.navigationController popToRootViewControllerAnimated:YES];
Happy Coding..