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

しかし、これら2つは機能しません..どうすればこれを達成できますか?

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 は、実際には UITabBarController であるのに、UITabBar のインスタンスであるように聞こえます。firstView と secondView は、UIView のインスタンスのように聞こえます。実際には UIViewController サブクラスのインスタンスです。tabItemOne と tabItemTwo は、実際には UINavigationController のインスタンスであるにもかかわらず、UITabBarItem のインスタンスのように聞こえます。)

于 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 に答える