I have a UITabBarController with 4 views/tabs. Each view is a UINavigationController.
How can I popToRootViewController on one of these UINavigationControllers then switch tabs and push a viewController onto another UINavigationController using animation throughout?
So the sequence would be:
At start we are in Tab 1's view which is a UINavigationController. A View has been pushed onto it beyond its root ViewController.
-Tab 1
- UINavigationController1
- RootViewController1
- SomeViewController1 [We are here]
-Tab 2
- UINavigationController2
- RootViewController2
A button is tapped in SomeViewController1 that causes the following:
UINavigationController1 pops to its root view controller (with animation)
UITabBarController switches tab to Tab2
SomeViewController2 is pushed onto UINavigationController2 (with animation)
So the view looks like this:
-Tab 1
- UINavigationController1
- RootViewController1
-Tab 2
- UINavigationController2
- RootViewController2
- SomeViewController2 [We are here]
int tabYouWantToSelect=2;
BOOL isNavigation=YES;
[[self.tabBarController selectedViewController].navigationController popToRootViewControllerAnimated:YES];
//if any controller is presented as a model view then
//[[self.tabBarController selectedViewController] dismissModalViewControllerAnimated:YES];
[self.tabBarController setSelectedIndex:tabYouWantToSelect];
//the newly pushed view controller's viewWillAppear
-(void)viewWillAppear:(BOOL)animated {
if(isNavigation){
[self.navigationController pushViewController:objAddLocation animated:YES];
}
}
Pop to rootview controller on the navigation controller you are currently showing in your UITabBar Controller
Change the tab programmatically
Push the viewController on the new tab's navigationController programmatically
All this should happen through your applications delegate implementation file.
If you need the code as well let me know...
Here is how I've done it. I feel it is much cleaner than infecting the root VC with code that isn't relevant to it.
I created a UINaviationControllerDelegate that checks the number of UIViewControllers left on its UINavigationController. If there is only one left it posts a stackAtRoot notification. Meanwhile just before I popToRootViewController I register a Command that is triggered by this notification. When it is triggered I have it orchestrate the tab switch and pushing of a VC onto the new tab's UINavigationController. It immediately unregisters the command, so it will not be called again unless reregistered.
Related
My application is view based app. First view is login view. After login view i have MainMenuCcontroller which has a tabBarController:
#interface RunnoMainMenuController : UIViewController {
IBOutlet UITabBarController *tabBarController;
}
From login view controller, i am going to MainMenuController using this line of code:
[self presentModalViewController:mainMenu animated:YES];
this controller has 4 tabs. Now i need to do some stuff in viewWillAppear of a tabBarItem. viewWillAppear is not called when i tap a tabBarItem. I have a button in one of those tabBarItem's view which pops up a table view controller using presentModalViewController. This tableView uses dismissModalViewControllerAnimated:YES to disappear it. When i pop up this tableview and dismiss it then viewWillAppear of every tabBarItem works fine. If i will dismiss modalViewController in MainMenuController then it will again go back to login view. How can i dismiss modalViewController without leaving current view or any other solution? Thanks in advance.
You may need to consider how your views are presented. The tab bar controller should always be the window's root view controller. From the Apple docs:
When deploying a tab bar interface, you must install this view as the
root of your window. Unlike other view controllers, a tab bar
interface should never be installed as a child of another view
controller.
Rather than present your login view as the root view and the tab bar as a modal view controller, try it the other way round. The tab bar controller as root, with the login view as presented as a modal view controller from the view controller of whichever tab is shown initially. Dismissing this will then reveal the tab bar controller.
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 simple uiviewcontroller with 4 buttons. Every buttonclick event loads a different image on the view. However for the 4th button i want to launch a navigation controller based uiview with a uitableview. The table view can then have 3 levels which define the settings for the application.
On selecting a row in the uitableview on the 3rd level i need to return to my main view with the selected row index.
How can i add a navigation based view which will be launched on a button press event and the first view of the uinavigationcontroller should compose of a back button which will close this navigation view and return to main view.
TIA,
Praveen S
Edit:
My first(home) view does not need a navigation bar. The view launched from the home view should however consist of a navigation bar with back button.
if(nxtv12==nil){
nxtv12=[[v12 alloc] initWithNibName:#"v12" bundle:nil];
}
[self.navigationController pushViewController: nxtv12 animated:YES];
and for coming back to home.
[self.navigationController popToRootViewControllerAnimated:YES];
Create a UINavigationViewController object in the current UIViewController (or use self.navigationcontroller) and push the new UIView into the navigation controller. To come back to the same view, use popToRootViewControllerAnimated in the new UIView class.
after reading a lot of tutorials and threads here on stackoverflow there is one basic question left in my head.
The structure of my App should be the following:
MainMenu - fullscreen without a navigation bar but 2 buttons (button1 and button2)
Page1 - should appear by pressing button1 and should have a navigation bar at the top with a "back"-button to get back to the MainMenu.
Page2 - should appear by pressing button2 without a navigation bar at the top. Page2 should be a UISplitView. There must be a back button somewhere.
(I think this is where the problem starts, a UISplitView can't be presented modally, can it?)
You should be able to add subpages to Page1.
So how can I do that? I don't need executable code but just a hint on how the structure of my app should be. For example where to add the navigation controller, how the MainMenu looks like.
Thanks in advance!
Are you trying to create an Application for iPad?
Your Application's UI sems inconsistent being First View the only view without navigation Bar.
You will be using standard navigation to navigate to page1 from home page. So you will be adding a navigation Controller with Home View Controller as a Root View COntroller with hidden navigation bar.
eg.
-(void)applicationDidFinishLaunching:...
{
HomeViewController * hvc = [[HomeViewController alloc]init];
UInavigationController * nvc = [[UINavigationController alloc]initWithRootViewController:hvc];
nvc.navigationBar.hidden = YES;
[window addSubView:nvc.view];
}
Then on tap of first Button you will be pushing the Page1 View Controller
-(IBActtion)button1Pressed:(id)sender
{
Page1ViewCOntroller * p1vc = [[Page1ViewCOntroller alloc]init];
[self.navigationController pushViewCOntroller:p1vc animated:YES];
}
In viewWillAppear: method of Page1ViewController unhide the NavigationBar and hide it in the viewWillDisappear: method
Your Page 2 needs to be splitViewController.
Now about Split View, Apple says
The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface.
But as there is no "must" written in the above statement, and since its finally a View Controller in itselt, you should be able to add it on the window or another view.
Try to create a VIewController, with split VIew added on it, and like page1, push the View on the navigation Controller.
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 ..