Tab Bar in View Based Application - XCode - iphone

How can I use Tab Bar in my View Based application in second view ?
EDIT :
(Suppose)My application contains four views. The navigation from firstView to secondView is simple , I want the Tab Bar on the secondView and connect rest of the two view with the Tab Bar.

On the other hand I think this has been discussed here: uitabbarcontroller / uitabbar in navigation based project
Just take a look.
EDIT: If it is a navigation based app and you want your tabbar on the second view, just initialize the navigation controller and use pushViewController message to it and push the tabBarController onto the navigation stack.
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1,viewController2,nil];
[self.navigationController pushViewController:tabBarController animated:YES];
Place this wherever you wish to push this tabBarController from the first view, where the first view is a navigation controller based entity and viewController1,viewController2 etc are the view controllers from the tab bar items.

Related

BarButtonItem not displayed when views of uisplitviewcontroller changed

My app works with tabbarcontroller as root view of the window, where on clicking each tab item loads splitviewcontroller with required views for it. The left and right panes of split views are navigation controllers. Now on any button action or didselectrow in tableview corresponding views are to be loaded in right pane. I succeeded loading views in right pane , but not able to display barbuttonitem when new view controller loaded in right pane of split view.
tabbarcontroller
-->splitviewcontroller
----->Leftpane:navigation controller
--------------->view controllers
----->Rightpane:navigation controller
--------------->view controller
Each Splitview of tab bar wil act like 'iPad Mail app' .
To make the app gernalised, I taken class RootiPadViewController which has the delegate of uisplitviewcontroller and uipopovercontroller which loads alls views in slpitview.
Loaded viewcontroller in right pane of split view as below.
UISplitViewController *splitViewController = (UISplitViewController*)[appDelegate.tabBarController.viewControllers objectAtIndex:tabIndex];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
//[navController pushViewController:viewController animated:YES];
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:[splitViewController.viewControllers objectAtIndex:0]];
[array addObject:navController];
splitViewController.viewControllers = array;
[array release];
Please suggest me why bar button item not displayed when views changed in splitviewcontroller.
App looks as below
I may be wrong but from my knowledge, the bar button item should appear only when you are in portrait mode, because:
a split view controller has two controllers (master and detail view controller)
both view controllers are shown on the screen when you are in landscape mode
when you are in portrait mode, only the detail view controller is shown, thus the bar button item appears
the bar button item goal is to let you open the master view controller in portrait mode
Please let me know if that helps you.
For Navigation Controller each view should define their left and right bar buttom items, if nothing defined then the tabbar will be empty . The only barbutton Item you will get free is the back barbutton item which appeared when you push a new View Controller above the rootViewController of the navigationController
You have to to allocate them in your ViewDidLoad method of each viewController in the NavigationControoler and set them as right and left barbutton item of your parentViewController(ie navigationController)
Please check this sample project https://github.com/alexth/TBSV
It's about how to use UISplitViewController inside UITabBar.
All logic is in Appdelegate's -loadSplitToTab Just total inheriting of all controllers, in every other cases UISplitViewController needs to be a root (as described in Apple documents) and you will not be able to use UISplitViewController inside UITabBar.

Displaying a UIView over the tab bar in a UITabBarController

I'm using a UITabBarController. Is it possible to display a UIView over the tab bar of the controller?
Use UIViewController with UITabBarControllerDelegate, add a UITabBar to it, set the delegate. You will be able to add UIViews over the view controller.
If you are talking about another view controllers view then present that view controller over the tab bar controller view.For ex. lets say About is the tab inside the ta bar controller.Then when you click on the About tab it will show one view controller which is inside the tab bar controller.In that view controller in view did load you can right the below code to see the view over the tab bar controller.
views=[[AboutUsViewController alloc] initWithNibName:#"AboutUsViewController" bundle:nil];
[self presentModalViewController:views animated:NO];

navigation controller doesn't show up iphone

I have an application with a tab bar as the root controller. I have four items in the tabbar. The second item is a table view and this should have a navigation controller of course, the thing is that i don't even get the navigation bar to show up and i have no idea how to do it. So i tried to guess after a long time in google without success. This is what i did in the viewDidLoad method:
SearchNavController *navController = [[SearchNavController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:navController];
[searchNavController release];
With that i got an IlegalArgumentException.
How can i get the navigation bar to show up?
Thanks in advance guys
Have a nice day!
Since you used interface builder to setup your tabbarcontroller. follow the following steps to get navigation bar and navigation controller in your tabbarcontroller:
Open Mainwindow.xib and select tababarcontroller .
In the attribute inspector , select the item1 in viewcontroller and from the arrows to the right change it to navigation controller.
Try this link:
link 1
Your navController should probably an ordinary UIViewController with the view you want to display. Also you need the following to actually display the navigationController:
[self presentModalViewController:navigationController animated:YES];
The navigation controller should now show up with your view as it's content.
IF you are using interface builder. Then Add UINavigation controller in each tab bar then add your view controller in uinavigation conrtroller. If you have 4 tabs then you have to put 4 navigation controller.
UITabbarcontroller ->>Tab Bar >>
UINavigationController >> set its class to your viewcontroller

how to create tabbar programmatically

HI all,
i am having navigation based application, in which i need too implement tab bars ,in one of view.
in one view i need 5 tabs, can any one please suggest me to create tab bars programmatically,, ? each tab should navigate to another xib.
Suggestions are always appreciated.
regards
Here is a sample code from Apple to create tab bar programmatically:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
MyViewController* vc1 = [[MyViewController alloc] init];
MyOtherViewController* vc2 = [[MyOtherViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
// Add the tab bar controller's current view as a subview of the window
[window addSubview:tabBarController.view];
}
More here
It's worth noting that a tab bar controller implemented inside a navigation controller is unsupported by Apple. From the same doc linked to by vodhkang above:
Note: Although a navigation controller can be embedded inside a tab, the reverse is not true. Presenting a tab bar interface from within a navigation interface is potentially confusing for users. A navigation interface uses one or more custom view controllers to present an interface focused on one goal, which is usually the management of a specific type of data. By contrast, the tabs of a tab bar interface can reflect completely different purposes in an application and need not be related in any way. In addition, pushing a tab bar controller on a navigation stack would cause the tabs to be displayed for that screen only and not for any others.
So instead of using UITabBarController consider implementing a tab bar with a UIViewController as the tab bar's delegate.

How to add a UINavigationController to my UITableViewControllerSubclass?

My app is a tab bar application, which one of the tabs is a TableViewController instead of a viewController which works fine (the table displays great) but where and how do I add UINavigationController to it? :-)
You can do this 2 different ways... in IB or code. If I'm dealing with a TabBar I usually do it in IB. All you have to do there is is drag a NavigationController object where your tableview object currently sits... then just make your tableviewcontroller the first child of your new navigation object.
TabBarController
-(Tab Bar)
-NavigationController
--(Navigation Item)
--TableViewController
or
If you want to do it in code... I would just set it up within your app delegate (usually because a tab bar is at the highest point in your app... meaning it appears right away after loading):
// Create a tabbar controller and an array to contain the view controllers
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:numberOfTabs];
// setup the view controllers
UINavigationController *myNavigationController;
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myTableViewController];
// add to tab bar controller
[localViewControllersArray addObject:myNavigationController];
tabBarController.viewControllers = localViewControllersArray;
// add the tab bar to the window
[window addSubview:tabBarController.view];
You should then release the objects you just created since they will be retained by the TabBarController and Navigation Controller. Hope this helps
As Ryan noticed you can make it easily using IB. Here is how you can achieve this:
Launch Xcode and create new Tab Bar Application project.
Under resources group find MainWindow.xib and double click it to open in Interface Builder.
Next, select Tab Bar Controller object and open Inspector window (Command + Shift + I).
Notice "View Controllers" section in Inspector () then click on View Controller popup and change value from View Controller to Navigation Controller.
That's it! Now you can use your UITableViewController subclass inside this UINavigationController.