I have an app which has three tabs in tab bar controller .Each tab bar item has a navigation controller and there is a log out button on first tab bar item.Now if i navigate into different naigation controllers and log out then all the navigation controllers remain in the same state for new user.I want all the navigation controleers to get to root when users logs out.
Try this:
for (UINavigationController *navController in myViewController.tabBarController.viewControllers) {
[navController popToRootViewControllerAnimated:NO];
}
i think your prob can be solved by writing a method for logging out and the method pops all the view controllers added to the root controller.when the user taps on the logout button all the view controllers should be popped and if needed call the action in all the three view controllers.
hope it would work..
jtbandes, your answer works really well, but what if I need to push the root view controller for only one tab? I don't want other tabs to be modifier, I just need to push the root view controller of one tab.
Related
So I have this application where I have a view controller (which I want to appear first when the app starts) and a tab bar controller. I also have other navigation bar controllers that are in the tab bar controller. I want to place my view controller on top of the tab bar controller. Making the tab bar controller the parent of the view controller would be better though.
But take note, I do not want a tab bar item to represent the view controller and I want the tab bar to appear along with the view controller. I do not and would not want to use storyboards as much as possible. How can i achieve this?
I guess the simplest solution would be to use a screenshot of your tabBar and put it in your HomeViewController as a button. In this case you could use your HomeViewController as rootViewController and in the button action you set the TabBarController as the rootViewController.
Root = Home + Button
-->
Root = TabBar
Perhaps you need four buttons, if you want the correct tab to be selected.
I have a tabbed application and each tab has a navigation controller with table views in it.
In one of the view from a tab, I want to present the first view controller of another tab.
My tabViewController.viewControllers has an array of navigation controllers for each tab.
I cant seem to present the view controller directly without accessing the navigation controller and I guess you cant present a navigation controller.
What am I doing wrong??
If I understood you correctly, you can access to your root controller something like that: [[tabViewController.viewControllers objectAtIndex:index] objectAtIndex:0], but I dont think you can display one view twice. So you still should recreate this view controller to display it in another tab as childViewController, for example
I am currently developing an app that has a TabBarController and each of the tabs contains a navigation controller. This way on each tab I can show details of the rows selected on a view by pushing the viewcontroller to the navigation controller. Each of the views also have an UINavigationItem above them. In this navigation item I placed a button.
But now I would like to change the viewcontroller for a certain tab, when clicking the button in the UINavigationItem, BUT the view(controller) I want to change to has to act like the root view controller of that tab.
So I do not want to push another view on the navigation controller, but just switch to that view (in the same tab) and have that act as the root view controller.
I cannot find a good way to do this, with actually having the views work correctly. They either do not dealloc when I switch views (which would be nice, because I want to keep memory usage to a minimum).
One way of solving this, might be that I add more tabs to my TabBar Controller and just switch to the right tabs when I click the button, but that would be a last resort.
Not really sure if I described this correctly, but I was wondering what the best way is to do this. My preference is having 3 viewcontrollers and switch between them.
Hopefully I understand your question correctly: you want to basically 'reset' your navigation controller to have a new root.
You can do this by telling your navigation controller that you want to display a new set of view controllers:
[navigationController setViewControllers:[NSArray arrayWithObject:newViewController]
animated:NO];
This will get rid of all view controllers currently on that navigation controller's stack, and reset the root view to newViewController.
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.
I have an application with a Tab Bar Controller that has three tabs.
In tab 1 there is a view (view1) with a button that when clicked transitions the user to a new view (view2) still within tab 1. However when this new view (view2) is loaded it covers my tab bar controller.
What is the best approach for me to take to still display tab bar controller as well as keep tab 1 highlighted?
How are you performing your "transition" to view2 from view1?
One solution is to use a UINavigationController as the root view controller for tab1, so view1 can display view2 by pushing it on the navigation controller. Alternatively, have view1 display view2 modally.
Either way should not cover your tab bar, and tab1 will still be selected (highlighted).
I think you are pushing the view as modal view if this is the case then the view will definitely cover your tab bar the other way to do this is push the view controller and this will not hide your tab bar.
Try to do it like:
[[self navigationController] pushViewController:viewContObject animated:YES];
Hope this helps,
Thanks,
Madhup