If I push a view onto a navigationController and present it modally, is it possible to push and show another view without having to first dismiss the modalViewController? Thanks.
Your question is not quite clear. "push a view onto a navigationController" and "present it modally" are 2 different operations. However, after doing either of these, you can do either of those again.
NavCon push ViewA
-ViewA can then push ViewB
or
-ViewA can present ViewB modally.
NavCon show ViewA modally
-ViewA can then push ViewB // this is a little weird, but possible.
or
-ViewA can present ViewB modally.
Related
I've got a hierarchy of 3 ViewControllers on a UINavigationController app.
Start in VC1, from there you can load VC2. In VC2 you can load VC3.
You can navigate backwards through the VC's by pressing the left nav button on the navbar.
But the designer wants to be able to jump from VC1->VC3, and then if you press the left navbar button to go back it will take you to vc2.
Is it possible to have have this kind of navigation with a NAV controller?
If the user wants to go VC1-VC3 can i push both VC2 and then VC3 onto the navigationController stack so that the navigation is maintained correctly.
Also if the user wants to go from VC3->VC1 can i pop both VC3 and then VC2 off the navigationController stack so that VC1 displays?
First - tell your designers that this kind of navigation is confusing for the users and they should take some more usability and UX classes. Second - yes it's possible - the easiest way would be to call
[navigationController setViewControllers:newViewControllers animated:YES];
This will replace the entire navigation stack, so ensure that it contains [VC1, VC2, VC3] (and whatever else might happen to be before them)
The normal back button will pop to the previous view controller. You could make a left bar button in you V3 which will pop to a given view controller in your hierarchy using the UINavigationController method (giving your V1 instance as viewController)
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
Push BOTH VC2 and VC3 onto the stack to preserve the navigation when pressing the back button. To go from VC3 to VC1 you can use...
[navigationController popToViewController:vc1 animated:YES];
or if VC1 is the root...
[navigationController popToRootViewControllerAnimated:YES];
I have a project based on Xcode's NavigationController template. This template has a navigationController and a RootViewController.
From inside this RootViewController I push a view and this view pushes a third view. Something like:
NavigationController >> RootViewController >> ViewController 1 >> ViewController 2
Now, from ViewController2 I want to access the navigationController and the navigationController.toolbar.
I know that every viewController has the navigationController property but my question do I have to do something when I push a new viewController so this variable (on the view that is being pushed) will have a valid reference to the correct ViewController or all pushed views will always have a valid reference to the navigationController?
The reason for my question is that I am trying to access the navigationController.toolbar, to make it invisible, and I am having no result.
thanks.
You might want to try -[UINavigationController setToolbarHidden:animated:] to hide the toolbar instead:
[self.navigationController setToolbarHidden:YES animated:YES];
This has always worked for me no matter how deep in the navigation stack my view controller was.
In the entire navigation stack of one UINavigationController object, every view controller's navigationController property has the same value.
The navController is like a box that contains the viewControllers within, with the last one to be pushed shown to the user until it is popped off, when the one below it will come to life again.
This means you can rely on the navController instance always being available from within a controller that was pushed by the navController.
I have a navigation controller that loads a tableview, from here the user can select a row which loads a detail view that gets pushed onto the stack. This detail view controller has a segmented control in the bottom bar which loads in a series of views using [self.view insertSubview:firstDetailViewController.view atIndex:0]; etc...
That works fine - one of the subviews loaded also contains a table which loads another detail view. This caused problems because I couldn't access the navigation controller from within the sub view. To do so I had to use:
YourAppDelegate *del = (YourAppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:nextViewController animated:YES];
Which I found here: Accessing a Top Navigation Controller from a Subview Navigation Controller.
But there's another instance where similar functionality is required. From the home view controller a lists view is loaded and presented modally. From here I push 2 detail views onto this new navigation stack using self.navigationController etc... which works fine. But when the subview tries to push the detail view it doesn't work. self.navigationController doesn't work, the appDelegate one pushes them onto the other nav controller and self.parentViewController.navigationController doesnt work.
Any ideas?
So your Home VC does presentModalVC of a table view. The table view does a self.NavCon pushVC: detail. And the detail then fails to push a sub-detail. Is that the scenario?
I'm wondering where the tableview got it's nav controller from, since it was presented modally, which does not require a NavCon.
I'm also wondering if you could push the tableview onto the NavCon instead of presenting modally; then the detail should have an intact NavCon which could then in turn push a sub-detail.
Hope that helps.
-Mike
my app first viewController is UIViewController.
and when user click button firstView disappear and push UITabViewController
is it possible?
i can't find how to push UITabViewController from UIViewController.
UPDATE sorry, I misread TabVC for UITableViewController. Do you mean UITableViewController or UITabBarController? I'll leave my answer below anyways.
In this instance, it's usually best to have a UITabBarController be the root view object. Although it can be done, it's a messier implementation, in my opinion.
I would in fact make the UITabBarController the root and display the UIViewController modally from that UITabBarController on launch.
The user would be presented with the UIViewController and when they clicked the button, dismiss that modal view, revealing the UITabBarController.
Just use a UINavigationController.
Use the navigation controller to push the tableView as the second level in the hierarchy. As a bonus you'll get the back button for 'free' and you don't have to worry about delegates for getting back to the original UIViewController.
you may try this:
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:2];
it should work because selectedViewController property contains view of selected tab.
First of all you have view controller . And make Second view controller which contain tabbarcontroller . Now just push second view controller . And add tabbarcontroller's view as a subview to second view controller .
Hope you gets it ..
I present a UIViewController modally but would like to push another ViewController from the modal view. How can this be done as pushViewController does not work from a modal view. Thanks
Use a UINavigationController as the view that you show modal. You can then push onto that controller.
I have used a slightly different approach than Mike's suggestion. I create a navigation controller (NC) and init it with a root viewcontroller of the view controller (VC) I want to present modally. I then present the nc modally. I can then successfully push from the VC when needed.