まず、UITabBarController への参照が必要です。IB で初期ビュー コントローラーとして設定されている場合、これは非常に簡単です。ストーリーボードを開き、UITabBarController の左側にある小さな灰色の矢印を探すことで、これを確認できます。その場合は、次のようにします。
UITabBarController *myTabBarController;
if ([_window.rootViewController isKindOfClass:[UITabBarController class]]) {
NSLog(@"This window's rootViewController is of the UITabBarController class");
myTabBarController = (UITabBarController *)_window.rootViewController;
}
UITabBarController を使用している場合は、次の方法で子 UIViewController への参照を取得できます。
[myTabBarController objectAtIndex:index];
TabBarController を直接クエリすることもできます。
NSLog(@"Selected view controller class type: %@, selected index: %d", [myTabBarController selectedViewController], [myTabBarController selectedIndex]);
ゼロベースのインデックス スキームは、プログラムまたは IB (一番左のタブ = インデックス 0) を介して設定したタブの順序に従います。
UITabBarController への参照を取得したら、残りは非常に簡単です。
LoginViewController* myLoginViewController;
if(![[myTabBarController selectedViewController] isKindOfClass:[LoginViewController class]){
//If the currently selected ViewController is NOT the login page
//Show timeout alert
}