首先,你需要有对的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,你就可以用其子UIViewControllers引用:
[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
}
我结束了有错误我感动的viewDidAppear登录后显示做同样的事情,而它在的appDelegate工作每隔一段时间在测试(发布)中它都会失败。希望我会首先看到这一点,但答案非常好。然而,发生了什么,我有一个独立的登录故事板和实际应用程序的主要故事板。感谢您的伟大答案... – 2013-11-26 19:32:25