で
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
行う
[viewController.navigationController popToRootViewControllerAnimated:YES];
これにより、タブが選択されるたびに、タブのビュー コントローラーがルート ビューに移動します。
メイン ウィンドウのビュー コントローラー (タブ バー コントローラー) のインスタンスをアプリケーション デリゲートのままにしておくことはまったく問題ありません。
追加する必要があるのは、次のように、デリゲートまたはその他の初期化されたクラスをタブ バー コントローラーのデリゲートに設定することです。
myTabBarController = [UITabBarController alloc ...
myTabBarController.delegate = self; // the app delegate will be also the tab bar delegate
アプリ デリゲートで、次のメソッドをアプリ デリゲートに追加します。
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
[viewController.navigationController popToRootViewControllerAnimated:YES];
}
タブ バー コントローラーは、タブが選択されるたびにこのメソッドを呼び出します。UITabBarControllerDelegate
また、アプリケーション デリゲートに次の方法で確認させることもできます。
@interface PSAppDelegate : UIResponder <UITabBarControllerDelegate>
これにより、アプリデリゲートがプロトコルでメソッドを宣言する必要がある、または宣言する可能性があることがコンパイラに通知され、このメソッドの非常に便利な自動補完も提供されます。