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
Related
I have a UIView (with identifierSplashScreen) which basically acts as a introduction view and displays a small animation. once the animation is completed i want the view to display a tabbar view which here in after will be the main view. no data of any kind is passed on from the first UIView to the second UIView(with identifier HomeScreen). I have seen most examples where the
secondViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self.navigationController pushViewController:svc animated:YES];
but this Pushes the view controller and a navigation bar with a back button appears which I dont want. Also I am never going to Return to the Splash Screen. it would be great if one of you could offer any help.
Iam a biggener and not a expert iOS programeer, so a simple code example will be of great help.
Instead of pushing onto the navigation stack why not replace the stack?
eg.
[self.navigationController setViewControllers:#[svc] animated:NO]
You can do a push segue and not have a navigation bar... Select your navigation controller and on the 4th tab on the right uncheck "Show Navigation Bar"
Is there any way to quickly go to rootViewController? I want to remove all views from the stack & return to rootViewController without even bothering the sequence of views on top of it.
From the docs:
popToRootViewControllerAnimated:
Pops all the view controllers on the stack except the root view controller >and updates the display.
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
Parameters
animated:
Set this value to YES to animate the transition. Pass NO if you are setting >up a navigation controller before its view is displayed.
Return Value:
An array of view controllers that are popped from the stack.
First I think you need to dismiss presented model then you can pop all the pushed view controllers. As presented model would not be in the stack of the navigation.
[self dismissModalViewControllerAnimated:YES];
Then you can pop to base view controller.
[self.navigationController popToRootViewController:YES];
Try this:-
[self.viewController popToRootViewController:YES];
I wan't to flip from one view controller to another for that i used following coding on button click
-(void)ClicOnLogout {
LogOutViewController *logOut=[[LogOutViewController alloc]initwithnName:str];
logOut.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:logOut animated:YES];
}
but when i m in logout view controller there is one button but it won't work so can any one give me the proper solution for it.
Thanx...
You should read that Apple documentation article on Modal View Controllers which explains everything you are asking there. Basically what you need to do on your logout view is to call :
[self dismissModalViewControllerAnimated:YES];
By calling this, the back (left-to-right) flip animation will be done automatically :
UIModalTransitionStyleFlipHorizontal
When the view controller is presented, the current view initiates a horizontal 3D flip from right-to-left, resulting in the revealing of the new view as if it were on the back of the previous view. On dismissal, the flip occurs from left-to-right, returning to the original view.
You can call the popViewControllerAnimated method:
[self.navigationController popViewControllerAnimated:YES];
or you can assign it to push it onto the navigation controllers stack:
[self.navigationController pushViewController: viewController animated:YES];
I'm trying to implement a navigation controller with some hierarchical views. I want to use a regular UIViewController to present choices for drilling down, I don't want to use the navigation bar - I want to have my own, custom buttons for returning back up a level.
I see examples like:
[[self navigationController] pushViewController:nextViewController animated:YES];
and my questions are these: Is navigationController a property of all UIViewControllers? Can I refer to self.navigationController regardless of the view that's on the stack? If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewController animated:YES];
Each view I present will need a button to return to the previous view, or to the root view, depending on the situation. I want to create that button in each view controller and control which view in the stack it returns to. Am I on the right track?
Is navigationController a property of all UIViewControllers?
Yes.
Can I refer to self.navigationController regardless of the view that's on the stack?
Every UIViewController on the UINavigationController's stack will return the UINavigationController object when calling navigationController on it.
If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewControllerAnimated:YES];
Yes. popToRootViewControllerAnimated: will take the user to the root UIViewController for the UINavigationController, and you can use [self.navigationController popViewControllerAnimated:YES]; to just pop off the top UIViewController. This last one does the same as tapping the Back UIBarButtonItem.
Am I on the right track?
Yes :)
I have an UIView added in the main window with a controller. On clik of a button on this view I want to load a UINavigationController which will migrate to multiple views pushing them one by one on stack. Now what I want to do is when user reaches at the end of views, in the last view I have a done button. ON clik of this button I want to move back to my first screen unloading the NavigationController from the memory.
What is the best way to do it since popToRootViewController takes you to the first screen of UINavigationController which is my second screen.
You basically want to remove the navigation controllers view, so why cant you just say [navigationController.view removeFromSuperView] ?
One way to do this is to present the navigation controller as a modal view controller, and dismiss it when you're done:
// In the parent controller, when the navigation controller is about to appear:
UINavigationController* navController = [[UINavigationController alloc] init];
[self presentModalViewController:navController animated:YES];
// ... later, in the nav controller, when it's done being used:
[self.parentViewController dismissModalViewControllerAnimated:YES];
[self autorelease]; // goodbye, cruel world (when the ar pool is drained)
A few ideas, in order of desirability
make Controller #1 the root view controller of the stack and then use popToRootViewController. Is there a good reason why you aren't doing this already? Keep in mind you can easily hide the navigation bar from any controller, if that's what you're afraid of.
Add a method called "destroyNavigationStack" or something to main Controller #1 and have a reference to controller #1 in your app delegate. In your Nth view controller, when "done" is hit, get a reference to your app delegate (UIApplication's sharedApplication method), and send View Controller #1 this "destroy" message. There really is no reason to even think about popping view controllers off of the stack since you just want to get rid of the entire stack anyway.
Make ViewController #1 a singleton and call destroyNavigationStack