开发者

iPhone: Add a Tab Bar controller programmatically to a navigation controller

I'm developing an iPhone application and I started out with the navigation based template. But now i'd like to add a Tap Bar controller 开发者_JS百科at the bottom and I would like to do this without using Interface Builder. Can anybody tell me how to do this? Thanks in advance!


This is not supported by the framework.

A tab bar controller can only be created as follows:

  • Directly in your application’s main window.
  • As one of the two root views in a split view interface. (iPad only)
  • Present it modally to display some data that requires its own mode-based organization.
  • Display it from a popover. (iPad only)

In other words, a tab bar controller can't be pushed onto a navigation controller.

More info here:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW1


If you are asking how to start with a navigation controller and then allow the user to navigate to a view with a tabbar, I do exactly this in my iPad app. Go to the website listed in my profile if you are interested to see how my app uses the tab bar.

Although, I used Interface Builder to accomplish it. In Interface Builder, I created sort of a master view that contains the tabbar control at the bottom and a "content" UIView above it. As the user tabs through views, the "content" view is programmatically assigned the view that the user is interested in.

I suppose you could also accomplish it without IB. Just use code this:

UITabBar *aTabBar = [UITabBar alloc] init];
[[self yourView] addSubview:aTabBar];

Of course, you will want to create tab bar items and assign view controllers to each item. You may also have to tweak the tab bar control's layout params so that it sits at the bottom of the view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜