iPhone:从TableView推送到UIViewController时Tabbar隐藏

时间:2010-05-05 14:13:45

标签: iphone

我在Tab栏中有四个Tab栏项,它是视图的底部,我有TableView。我是以编程方式添加标签栏和项目(参见下面的代码)而不是通过I.B. 单击前三个Tab栏项,将在同一个TableView本身中显示数据。但是点击最后一个标签栏项将推送到另一个UIViewcontroller并在那里显示数据。这里的问题是,当我点击最后一个标签栏项目时推送到viewController,主“标签栏”被删除。

标签条形码:

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];

从上一个标签栏项目中按下控制器代码:

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

当我将当前的TableView推送到myViewController时,我没有看到底部的Tab栏。我在那里看到全屏视图。我想在点击每个标签项时始终看到底部标签栏。 这可能是什么问题?遇到此问题的人,请与我分享您的建议吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

您最初使用TabBar本身(作为视图)作为主视图。

像这样使用UITabBarController

//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];