iphone - 如何停止标签栏的第二次点击弹出到导航 Controller ?

标签 iphone uinavigationcontroller uitabbarcontroller root

我有一个基于标签栏的应用程序。所有选项卡都有一个导航 Controller 作为根。 如果用户再次点击该选项卡(如果该选项卡处于事件状态),它将弹回到导航 Controller 。

我怎样才能阻止这种行为?

所以事实上我有一个导航 Controller +一个隐藏的 viewcontroller做出一些决定+另一个 View Controller 。对于原始问题中的误导性信息表示歉意。我用的是隐藏的viewcontroller对于所有选项卡,其中 3 个,因为如果用户未登录,我在所有 3 个选项卡上都有登录屏幕。如果用户登录,那么我会弹出登录屏幕,并输入 1,2,3个人viewcontrollers在每个选项卡上。

第一次点击:

 0 : class=Crossing: 0x645c8a0>  
 1 : class=FavoritesViewController: 0x64ac140>  
 shouldSelectViewController : UINavigationController  
 UINavigationController topclass:FavoritesViewController  
 myTabBarController.selectedViewController :UINavigationController  
 did disappear  
 didSelectViewController : UINavigationController  
 UINavigationController topclass:FavoritesViewController  

第二次点击:

 0 : class=Crossing: 0x645c8a0>  
 1 : class=FavoritesViewController: 0x64ac140>  
 shouldSelectViewController : UINavigationController  
 UINavigationController topclass:FavoritesViewController  
 myTabBarController.selectedViewController :UINavigationController  
 didSelectViewController : UINavigationController  
 UINavigationController topclass:Crossing  

最佳答案

@MarkGranoff 这样做是正确的,但实现它的方法是这样做:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    if ([tabBarController.viewControllers indexOfObject:viewController] == tabBarController.selectedIndex)
    {
        return NO;
    }
    else
    {
        return YES;
    }
}

或者以更简洁的方式:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return (viewController != tabBarController.selectedViewController);
}

如果您只想阻止某个选项卡的默认行为,那么您可以执行以下操作:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSUInteger indexOfNewViewController = [tabBarController.viewControllers indexOfObject:viewController];
    // Only the second tab shouldn't pop home 
    return ((indexOfNewViewController != 1) ||
            (indexOfNewViewController != tabBarController.selectedIndex));
}

关于iphone - 如何停止标签栏的第二次点击弹出到导航 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6585899/

相关文章:

iphone - 文本字段键盘不出现

iphone - 在文本字段上崩溃单击 iOS 6.0 和 xcode 4.5

ios - NSURLSession "completion handler"内的导航不起作用

ios - 从 UITabBarController 中关闭

swift - 如何在 Swift 中呈现独特的 UITabBarController

iphone - 如何将表格 View 页脚颜色设置为与导航相同?

ios - 允许使用仅纵向应用的横向视频

iphone - UINavigationBar 自定义色调停止按钮点击颜色更改

ios - 如何解决 ios 7 中 ui 标签栏的奇怪行为

ios - 从自定义 View 的连接检查器中隐藏 socket