ios - ios中的选项卡栏打开一个选择器,而不是一个 View

标签 ios tabs uitabbarcontroller uitabbar

我有一个带有多个选项卡的选项卡栏应用程序,这一切都没有问题。每个选项卡都会转到一个新页面并打开一个新 View 。

我想做的是添加一个选项卡,它不会打开新页面或新 View Controller ,但会在当前页面顶部弹出一个选择器 View 。从该选择器中选择一个选项将跳转到新 View 。

所以在标签中:

第 1 页/第 2 页/第 3 页/选择器

前 3 个选项卡中的任何一个都会立即跳转到新页面。第 4 个选项卡打开带有第 4 页/第 5 页等选项的选择器,选择其中一个然后转到该页面。

如果您取消选择器 View ,该应用会停留在当前页面/选项卡上。

这在技术上是否可行,Apple 准则是否允许此类行为?

最佳答案

您需要子类化 UITabBarController,并实现此方法:

- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController
{
    NSInteger tabIndex = [[tbController viewControllers] indexOfObject:viewController];

    //Check to see if the selected index is the one you want to do something else, in this example, it's the second tab, so index is 1
    if(tabIndex == 1)
    {
        //Write the code you need to pop up the picker here.
        return false;
    }

    return true;
}

这将阻止选项卡栏实际显示一个新的 View Controller ,相反,您可以对其进行编码以执行任何您想要的操作。请注意,您仍然需要为该选项卡使用某种占位符 View Controller ,即使您永远不会查看它。它只需要保留一个位置,以便标签栏 Controller 知道它需要一个标签。

关于ios - ios中的选项卡栏打开一个选择器,而不是一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16487657/

相关文章:

Android FragmentTabHost 添加水平滚动

java - 选项卡小部件在 android 4.0 中始终使用大写字母

ios - 如何将标签栏 Controller 作为 subview 添加到父 View ?

ios - ASCellNode 中的 UIImageView+Kingfisher 缺少图像

android - 哪个更安全 : External browser or ChromeTab for authorization?

android - TabLayout不显示文本

ios - UITabBarController setSelectedIndex 性能低下

ios - (iOS) 以编程方式退出应用程序。

ios - 如何将 Date(1440156888750-0700) 这样的日期转换为 Swift 可以处理的东西?

iphone - 以编程方式切换到 TabBar 选项卡 View ?