0

iOS5でxcodeでストーリーボードを使用しています。6 つのタブを持つ TabBarController があります。TabController の前に、ユーザーはアカウント A または B のタイプを選択します。タイプ B が選択されている場合、タブの 1 つを非表示にしたいと思います。

UITabBarController のサブクラスがあり、このコードは機能しますが、私が望むものではありません。

if (accountType == 2) {
     [[[[self tabBar] items] objectAtIndex:1] setEnabled:NO];
}

これにより、2番目のタブが暗くなり、使用できなくなりますが、これが機能することを本当に望んでいました...

[[[[self tabBar] items] objectAtIndex:1] setHidden:YES];

しかし、それはこのエラーを引き起こします: -[UITabBarItem setHidden:]: 認識されないセレクターがインスタンス 0x856f490 に送信されました *キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。

これを達成する別の方法はありますか?

4

2 に答える 2

1

d.ennisの答えは私を正しい方向に向けました。ストーリーボードを使用して ios5 用に微調整する必要があります...

// load the storyboard by name
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

if (accountType == 1) {
   UIViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:@"First"];
   UIViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"Second"];
} else {
   UIViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:@"First"];
   UIViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"Second"];
   UIViewController *tvc = [storyboard instantiateViewControllerWithIdentifier:@"Third"];

}    

tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;

NSArray *controllersForTabBar = [NSArray arrayWithObjects: fvc, svc, nil];

[tabBarController setViewControllers:controllersForTabBar animated:NO];

[self.view addSubview:tabBarController.view];
于 2012-06-21T20:54:58.717 に答える