私の iPhone アプリケーション内には、ボタンを押すといくつかのビューから表示される3 つのタブを持つ共通のタブ バーがあります。私が従ったアプローチは、Robert Conn の投稿で説明されている Tweetie アプリケーションのワークフローでした。
メイン コントローラーはナビゲーション コントローラーであることに注意してください。タブ バーはナビゲーション スタックのビュー コントローラーの NIB ファイルに配置され、タブ間の切り替えの効果はデリゲートの didSelectItem メソッドで処理されます。
@interface GameTabBarController : UIViewController<UITabBarDelegate> {
UITabBar *tabBar;
UITabBarItem *lastGameTabBarItem;
UITabBarItem *previousGamesTabBarItem;
UITabBarItem *myBetsTabBarItem;
NSArray *viewControllers;
UIViewController *currentViewController;
}
@implementation GameTabBarController
...
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
UIViewController *viewController = nil;
// Get the view controller linked to the tab bar item pressed
...
// Switch to the view
[self.currentViewController.view removeFromSuperview];
[self.view addSubview:viewController.view];
self.currentViewController = viewController;
}
...
@end
タブ バーのビューは、アプリケーションの元のビュー コントローラーに応じてカスタマイズする必要があるため、GameTabBarController
タブ バーを持つ NIB ファイルの親クラスにしました。次に、いくつかの子クラスを作成しました。
@interface FirstGameTabBarController : GameTabBarController {
...
}
@interface SecondGameTabBarController : GameTabBarController {
...
}
...
私の問題は、一部の子クラスで、親クラスに関連付けられている NIB ファイルの 3 番目のタブを削除したいということです。しかし、関連する UITabBarController がないため、Web で見られる典型的なアプローチ (つまり、タブ バー アイテムのビュー コントローラーを削除する) に従うことはできません。
どうやってやるの?以前に NIB ファイルに追加された要素を削除することはできますか?
ありがとう!!
UPDATE ソリューションはとても簡単でした...ビューコントローラーの代わりに、タブバーのアイテムを置き換えるだけです:
NSMutableArray *items = [NSMutableArray arrayWithArray:self.tabBar.items];
[items removeObjectAtIndex:2];
[self.tabBar setItems:items];
正しい方向に向けてくれた@Praveen Sに感謝します。