2012-01-28 7 views
2

私はこれを試しても動作しません。タブバーの項目が見えません。どうすればこの問題を解決できますか?ご協力いただきありがとうございます。タブ(ZiyaretFormTab5にZiyaretFormTab1)に入り、あなたのビューコントローラのそれぞれにおいてプログラムでタイトルをタブバーアイテムに設定するにはどうすればよいですか?

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 

myTabBarController = [[UITabBarController alloc] init];   
tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:@"ZiyaretFormTab1" bundle:nil]; 
tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:@"ZiyaretFormTab2" bundle:nil]; 
tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:@"ZiyaretFormTab3" bundle:nil]; 
tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:@"ZiyaretFormTab4" bundle:nil];  
tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:@"ZiyaretFormTab5" bundle:nil]; 

myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1, tab2,tab3,tab4,tab5,nil]; 
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1]; 
[tabItem setTitle:@"theTitle"]; 

[self.view addSubview:myTabBarController.view];  
myTabBarController.selectedIndex=0; 

} 
+0

1時間前から質問が重複している可能性があります[プログラムでタブバーコントローラにタイトルを設定できません](http://stackoverflow.com/questions/9044331/i-can-not-set-title-to-私のプログラム可能なタブバーコントローラ)。質問を再投稿しないでください。 –

答えて

2

initWithNibまたはのviewDidLoad機能にこのコードを挿入します。

UITabBarItem * tabtitle = [[UITabBarItem alloc] initWithTitle: @"title" 
                  image: nil //or your icon 
                   tag: 0]; 

    [self setTabBarItem: tabtitle]; 
+0

私はこれを試しても動作しません:S –

0

タブバーのタイトルは、それぞれのビューコントローラによって制御されます。タイトルを設定する最も簡単な方法は、タブで直接設定するのではなく、そのタブのビューコントローラ内から行う方法です。

各ビューコントローラには、タブバーとナビゲーションバーにタイトルを設定するためのtitleプロパティがあります。また、tabBarItemプロパティを持っています。このプロパティは独自のtitleプロパティで、タブを設定してナビゲーションバーには影響を与えない場合に設定できます。

だからあなたのViewControllerののviewDidLoadに、あなたが書くことができます:

self.tabBarItem.title = @"theTitle"; 
+1

私はこれを試しても動作しません:S –

+1

このコードをあなたのZiyaretFormTab1コントローラクラスのviewDidLoadに入れましたか? –

+1

私はこのコードを書いています。ZiyaretFormTab1のviewDidLoad –

0

はAppDelegateにタブ設定を置きます。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

訪れ、あなたの名前とアイコン情報の制服を置く:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = @"Kulağını tersten tutmana gerek yok"; 
    self.tabBarItem.image = [UIImage imageNamed:@"ringtab.png"]; 

    } 
    return self; 
} 
0
UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:0]; 
[item setTitle:@"fgfdgd"]; 
0

をあなたがそれを割り当て、初期化後

[tab1 setTitle:@"Your Title"] 

を設定しようとしています。

関連する問題