简体   繁体   English

在委托方法tabBarController shouldSelectViewController中检查所需的视图控制器:

[英]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.

相关问题 tabBarController:shouldSelectViewController:设置委托时不调用 - tabBarController:shouldSelectViewController: not being called when delegate is set 从View Controller调用TabBarController委托-Swift - Call TabBarController delegate from View Controller - Swift Xamarin forms:如何访问“tabBarController:shouldSelectViewController:” - Xamarin forms: How to access “tabBarController: shouldSelectViewController:” UIAlertview 委托方法不在子视图控制器中调用 - UIAlertview Delegate Method not calling in Child View Controller 从视图控制器调用应用程序委托方法 - Call app delegate method from view controller 在UiTabBarViewController中实现shouldSelectViewController方法 - Implementing shouldSelectViewController method in UiTabBarViewController TabBarController setSelectedIndex-将调用哪个委托方法 - TabBarController setSelectedIndex - Which delegate method will be called 目标视图控制器上的简单委托方法或属性 - Simple delegate method or property on destination view controller 从标签栏控制器显示的拆分视图控制器 - Split View Controller displayed from a tabbarcontroller 在视图控制器中隐藏tabBarController上的选项卡 - Hide a Tab on tabBarController from a view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM