我在TabBarItems
中有3 UITabBarController
:
<UINavigationController: 0xc76a680>
<SplitViewController: 0xc76a170>
<UINavigationController: 0xca5e6f0>
我在AppDelegate
中有方法:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
NSLog(@"tab selected index %@",viewController);
if (viewController == nil ) // I NEED TO IMPLEMENT A CHECk HERE
{
//show popup
return NO; //does not change the tab
}
return YES; //does change the tab
}
那么如何检查应该选择的视图控制器是第二个导航控制器? THX
答案 0 :(得分:6)
试试这段代码
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
BOOL result;
if (viewController == [self.tabBarController.viewControllers objectAtIndex:2]) //assuming the index of uinavigationcontroller is 2
{
NSLog(@"Write your code based on condition");
result = NO;
}
else {
result = YES;
}
return result;
}
答案 1 :(得分:0)
您可以检查viewcontroller.title属性,然后做出决定。假设两个视图控制器的标题不同。