views:

465

answers:

3

Hello all, I have an app with a navigation controller that I would like to add a tab bar to. Does anybody know if its possible to say something like if the fist tab is selected show view1 if tab 2 is selected show view2? If theres code for that then I would be good to go. Any help is appreciated. Y+Thanks

A: 

Why do you not want to use a TabBarController?

Otherwise you can simply add a tabbar and implement the UITabBarDelegate protocol to react to changes. Which is essentially implementing your own TabBarController.

You will need to create a Tabbar and set the delegate to an object that implements the following method, where you can switch view based on the selected tabbarItem:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
   int index = [tabBar.items indexOfObject:item];
   switch (index) ...
}
Felix
I cant use a tabBarController with this app the way its set up and many posts on here say when adding to a UINavigationController to not use a tabBarController. I just need to be able to add a UITabBar.
Tanner
We use a navigationController within a TabbarController without an issue.
Felix
Yes I have to many times. This app cant. Is there any way for a tabBar to switch views
Tanner
I have added a bit of code.
Felix
See my current NavController was being used and had a + button at the top where it would push a programatically done view not a xib. I did try to add a controller but it made the + button nil. When I alloc] init] the view it didnt respond. With the code above how do I tell it if section 2 is pushed to load view2?
Tanner
Your problem is not with the navController. It is trivial to push a controller that creates it's view programatically. You've got a problem elsewhere.
TechZen
A: 

You shouldn't be using a UITabBarView without a UITabBarViewController.

Jasarien
A: 

According the interface guidelines, a tabbar should always be at the top level of the app. In other words, you should have a tabbar and then have a navigation controller inside each tab.

If you need to display views as with a tabbar but not at the top level of the app, use a segmented control. Users will understand they are choosing alternate views but they won't be confused about where in the app they are.

TechZen
Thanks for the reply. I have the tab bar controller now as the root but it has made the button at the top left ( + ) nil and the next view is not presented. However when the tab is gone everything works fine. After running the debugger all I get is this: 2010-02-13 17:59:21.427 AirList[10138:207] Application tried to push a nil view controller on target <UINavigationController: 0x11a780>. After placing breakpoints I cant find anything special or leading to whats wrong.
Tanner
I would actually preffer the UISegmentedControl. Can you please tell me how to make the second half push a different view?
Tanner
Ive used this so far but it doesn seem to work. - (IBAction)seg:(id)sender{ UISegmentedControl *segmentedControl = (UISegmentedControl *) sender; NSInteger selectedSegment = segmentedControl.selectedSegmentIndex; if (selectedSegment == 0) { //toggle the correct view to be visible [HeroListViewController setHidden:NO]; //[secondView setHidden:YES]; } else{ //toggle the correct view to be visible //[firstView setHidden:YES]; [HeroListViewController setHidden:NO]; }}
Tanner