如何限制 UITabBarController 上的选项卡数量?
我有一个带有 UITabBarController 的 iPhone 应用程序。一切都很好。该应用程序的选项卡数量超出了显示屏纵向宽度所能显示的选项卡数量,因此我们总共看到 5 个选项卡(最后一个是“更多”选项卡)。问题是,我们希望将一些“不太有趣”的事情放在“更多”选项卡后面。我知道如果我只有 2 个视图控制器,那么我只会看到 2 个选项卡,依此类推,直到超过 5 个选项卡。
我们怎样才能只显示 4 个选项卡(3 个加一个“更多”选项卡),而不是 5 个?
我的猜测是:仅通过设置一个属性是不可能的(这肯定很方便!),因为我在文档中找不到任何内容,或者坦率地说,在这里找不到其他建议。
缺少实现我自己的“更多”选项卡,并为选项卡栏控制器提供仅 4 个视图控制器(最后一个是我自己的“更多”控制器),任何提示、技巧或提示都值得赞赏。谢谢!
I have a working iPhone app with a UITabBarController. It all works fine. The app has more tabs than can be shown across the portrait width of the display, so we see 5 tabs in total (the last being the "more" tab). The thing is, we want to relegate some of the "less interesting" things to be behind the "more" tab. I know that if I had just 2 view controllers, then I'd see just 2 tabs, and so on until I exceeded 5 tabs.
How can we show just 4 tabs (3 plus a "more" tab), instead of 5?
My guess is: this is not possible by just setting an attribute (which would certainly be convenient!), since I cannot find anything in the docs, or here frankly, to suggest otherwise.
Short of implementing my own "more" tab, and supplying the tab bar controller with only 4 view controllers (the last being my own "more" controller), any tips, tricks, or hints are appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是想结束这一切。最后,我实现了自己的“更多”控制器,并为 UITabBarController 提供了 4 个视图控制器,最后一个是我的更多控制器。
自定义 More 控制器只不过是我在创建 UITabBarController 的主选项卡和关联控制器时创建的通用 UITableViewController 子类。然后,我将行标题和相应的 UIViewController 添加到“更多”视图控制器中的数组中。当该选项卡可见并且点击一行时,我只需推送适当的视图控制器。
整个效果看起来完全“普通”,除了我有 4 个选项卡而不是 5 个。它的实现也比我想象的要简单。总是有奖金。
希望这可以帮助某人。
Just wanted to wrap this up. In the end, I implemented my own "More" controller, and supplied the UITabBarController with just 4 view controllers, the last being my More controller.
The custom More controller is little more than a generic UITableViewController sub-class that I create when I create the UITabBarController's main tabs and associated controllers. I then add row titles and corresponding UIViewControllers to an array in the More view controller. When that tab is visible and a row is tapped, I just push the appropriate view controller.
The whole effect looks totally "stock", except I have 4 tabs instead of 5. It was less of a hassle than I thought it would be to implement, as well. Always a bonus.
Hope this helps someone down the line.
这对于标准 UITabBarController 来说似乎是不可能的。我也不认为其他人遇到过这个问题,并且已经为您解决了。
This does not appear to be possible with the standard UITabBarController. I also don't think anyone else has run into this problem, and solved it for you already.
您要么必须子类化
UITabBarController
,这可能会有点混乱,要么像您提到的那样编写自己的选项卡栏控件。正如@blueberryfields 提到的,确实没有其他办法解决这个问题。在处理这个问题时,自定义选项卡栏似乎很常见,如果您确实一次只显示 3 个选项卡,我建议您采用这种方法。You are either going to have to subclass
UITabBarController
, which could get a bit messy, or just write your own tab bar control like you mentioned. There is really no other way around it as @blueberryfields mentioned. Custom tab bars seem pretty common when dealing with this issue, and I suggest going that route if you are really set on only showing 3 tabs at a time.