2016-07-19 10 views
0

iOS 9では、タブに表示されるビューコントローラは、tabBarItemです。しかし、タブ・バー・コントローラーは、必要に応じて各タブのビュー・コントローラーのみをロードします。最初は、タブ1のビューコントローラをロードするだけです(アプリが最初のタブで起動した場合)。したがって、ストーリーボード内の各タブ項目のタイトルを設定しない限り、その時点でロードされている唯一のビューコントローラであるため、最初のタブのみがタイトルを表示します。アイコンはローカライズする必要がないため、ストーリーボード)。iOS:タブを選択する前のタブバー項目のタイトル

どのようにストーリーボードを使用せずにすべてのタブのタイトルを設定できますか?

答えて

1

あなたはtabBarItemタイトルを配列にすべてのタイトルを入れて、事前に設定することができます

if let tabTitles = self.tabBarController?.tabBar.items as? [UITabBarItem] 
    { 
     tabTitles[0].title = "Messages" 
     tabTitles[1].title = "Contacts" 
    } 
+0

恐ろしいです!それはうまくいきました。 – RyJ

0

コード希望の下には、このヘルプを試してみてください、あなた

// MyTabBarController.h

#import <UIKit/UIKit.h> 
@interface MyTabBarController : UITabBarController 
@end 

// MyTabBarController.m

#import "MyTabBarController.h" 
@interface MyTabBarController() 

@end 

@implementation MyTabBarController 

- (void)viewDidLoad {[super viewDidLoad]; 
[self customizedTabbar]; 
} 
-(void)customizedTabbar 
{ 
UITabBar *tabBar = self.tabBar; 
UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 

UIImage *img1= [[UIImage imageNamed:@"t1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

UIImage * img1_sel= [[UIImage imageNamed:@"t1_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

    UIImage *img2= [[UIImage imageNamed:@"t2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

UIImage *img2_sel= [[UIImage imageNamed:@"t2_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

item0 = [item0 initWithTitle:@"Tab1" image:img1 selectedImage:img1_sel]; 

item1 = [item1 initWithTitle:@"Tab2" image:imag2 selectedImage:img2_sel]; 
} 

ありがとうございました

関連する問題