开发者

How to limit the number of tabs on a UITabBarController?

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. T开发者_开发问答hanks!


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜