tags:

views:

182

answers:

1

Hello all,

I have four Tab bar items in a Tab bar which is being bottom of the view where i have the TableView. I am adding Tab bar and items programmatically (Refer below code) not through I.B. Click on first three Tab bar items, will show the data in the same TableView itself. But clicking on last Tab bar items will push to another UIViewcontroller and show the data there. The problem here is, when i push to the viewController when clicking on last Tab bar item, main "Tab bar" is getting removed.

Tab bar code:

UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 376, 320, 44)];
item1 = [[UITabBarItem alloc] initWithTitle:@"First Tab" image:[UIImage imageNamed:@"first.png"] tag:0];
item2 = [[UITabBarItem alloc] initWithTitle:@"Second Tab" image:[UIImage imageNamed:@"second.png"] tag:1];
item3 = [[UITabBarItem alloc] initWithTitle:@"Third Tab" image:[UIImage imageNamed:@"third.png"] tag:2];
item4 = [[UITabBarItem alloc] initWithTitle:@"Fourth Tab" image:[UIImage imageNamed:@"fourth.png"] tag:3];
item5 = [[UITabBarItem alloc] initWithTitle:@"Fifth Tab" image:[UIImage imageNamed:@"fifth.png"] tag:4];
NSArray *items = [NSArray arrayWithObjects: item1,item2,item3,item4, item5, nil];
[tabBar setItems:items animated:NO];
[tabBar setSelectedItem:item1];
tabBar.delegate=self;
[self.view addSubview:tabBar];

Push controller code clicking from last Tab bar item:

myViewController = [ [MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
        myViewController.hidesBottomBarWhenPushed=NO;
        [[self navigationController] pushViewController:myViewController animated:NO];

I am not seeing bottom Tab bar when i push my current TableView to myViewController. I am seeing full screen view there. I want to see bottom Tab bar always when every tab item clicked. What might be the problem here? Could someone who come across this issue, please share your suggestion to me?

Thank you.

A: 

You are using the TabBar itself (as view) as the main view initially.

Use UITabBarController like this:

//tabBarController is defined in the interface (the .h file)
tabBarController = [[UITabBarController alloc]init];

firstViewController = [[UIViewController alloc] init];
UITabBarItem *item1 = [[[UITabBarItem alloc]initWithTitle:@"First" image:nil tag:1] autorelease];
[firstViewController setTabBarItem:item2];

secondViewController = [[SecondViewController alloc]init];
UITabBarItem *item2 = [[[UITabBarItem alloc]initWithTitle:@"Sec" image:nil tag:1] autorelease];
[secondViewController setTabBarItem:item2];

//init the tab bar controller populated with two view controllers
[tabBarController setViewControllers:[NSArray arrayWithObjects:firstViewController,secondViewController,nil] animated:NO];

[window addSubview:tabBarController.view];
medopal
Is your code correct? I tried this way, but observing two problems. One is, TableView has got struck, not scrolling. Second is, how do i add Tabbar item as i have only one tableview and accessing only one tableview for all three Tabbar items click, except the last one tabbar item.
Hi, I am having a TableView and adding TabBar programmatically in the bottom view as i written in actual post message. I am calling the same TableView itself when clicking on three Tabbar items. But for the fourth Tabbar item, i need to push to another viewcontroller. In this case, I need to maintain the Tabbar always in the bottom, but Tabbar is getting removed when pushViewController called. Could someone guide me properly?
check this: http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.3124430053.03124430055, a free iPhone dev course from Stanford University, the 7th lecture is about Tab Bar.
medopal