2

我是 iPhone 开发的新手......现在我正在尝试构建一个应用程序,我在其中以UITabbarController编程方式创建,如下所示:

UITabBarController *tabbar = [[UITabBarController alloc] init];
firstViewController  *firstView = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];

UINavigationController *tabItemOne = [[[UINavigationController alloc] initWithRootViewController: firstView] autorelease];
secondViewController *secondView = [[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];

UINavigationController *tabItemTwo = [[[UINavigationController alloc] initWithRootViewController: settings] autorelease];
tabbar.viewControllers = [NSArray arrayWithObjects:tabItemOne, tabItemTwo,nil]; 
tabbar.view.frame = CGRectMake(0,0,320,460);

[self.view insertSubview:tabbar.view belowSubview: firstView.view];
[self presentModalViewController:tabbar animated:NO];

在此,我如何向tabbar这些控制器添加标题。我试过了:

firstView.title = @"First View";

tabItemOne.title = @"First View";

但这两个不起作用..我该如何做到这一点?

4

4 回答 4

3

设置aViewController.title设置navigationItemtabBarItem标题。如果您希望navigationItemtabBarItem具有不同的title,请执行此操作,

// First set the view controller's title
aViewController.title = @"First View Tab";

// Then set navigationItem's title
aViewController.navigationItem.title = @"First View";
于 2011-07-15T05:29:27.267 回答
0
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"First View" image:[UIImage imageNamed:@"First View.png"] tag:0];
[tabItemOne setTabBarItem:item];
[item release];

如果我是对的。

于 2011-07-15T04:46:31.560 回答
0

要为控制器选项卡设置标签,请执行以下操作:

tabItemOne.tabBarItem.title = @"First View";

(顺便说一句,您可能需要重新考虑您的变量名称。它们非常令人困惑。tabbar 听起来应该是 UITabBar 的一个实例,而它实际上是一个 UITabBarController。firstView 和 secondView 听起来像 UIView 的实例,当它们是实际上是 UIViewController 子类的实例。tabItemOne 和 tabItemTwo 听起来像 UITabBarItem 的实例,但它们实际上是 UINavigationController 的实例。)

于 2011-07-15T05:17:18.443 回答
0
UITabBarItem *item= [[[[appDelegate tabBarController]tabBar]items ]objectAtIndex:0];
       //item.image=[UIImage imageNamed:@"hometab.png"];
       item.title=@"First View";

    item= [[[[appDelegate tabBarController]tabBar]items ]objectAtIndex:1];
       //item.image=[UIImage imageNamed:@"hometab.png"];
       item.title=@"Second View";
于 2011-07-15T06:16:23.847 回答