ユーザーがアプリにログインした後、いくつかのビューコントローラーとUITabBarControllerを作成します。これらは、アプリの残りの部分で永続化されます。そのためのコードは次のとおりです。
.......
//construction of view controllers, standard
NSMutableArray *topLevelControllers = [[[NSMutableArray alloc] init] autorelease];
[topLevelControllers addObject: paymentNavController];
[topLevelControllers addObject: customerNavController];
[topLevelControllers addObject: historyNavController];
UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.delegate = self;
[tabBarController setViewControllers:topLevelControllers animated:NO];
tabBarController.selectedIndex = 1;
次に、customerNavControllerにテーブルビューがあり、ユーザーをpaymentNavControllerに切り替えて、tabBarControllerの選択されたインデックスも切り替えたいとします。
では、含まれているビューコントローラの1つから、そのUITabBarControllerにアクセスするにはどうすればよいでしょうか。