[英]Check the needed view controller in delegate method tabBarController shouldSelectViewController:
I have 3 TabBarItems
in UITabBarController
: 我在UITabBarController
有3个TabBarItems
:
<UINavigationController: 0xc76a680>
<SplitViewController: 0xc76a170>
<UINavigationController: 0xca5e6f0>
And I have the method in AppDelegate
: 我在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
}
So how to check that view controller which should be selected is the second Navigation Controller? 那么,如何检查应该选择的视图控制器是第二个导航控制器呢? Thx 谢谢
try this code 试试这个代码
- (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;
}
You could check for viewcontroller.title property and then make the decision. 您可以检查viewcontroller.title属性,然后做出决定。 Assuming that title for both viewcontrollers are different. 假设两个视图控制器的标题都不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.