开发者

How to set the UITabBars items property when accessing through a UITabBarController?

I have build a UITabBarController programmatically and populated its viewControllers property. When I run this the tabBar buttons are, of course, empty, I tried to access the tabBar property on the UITabBarController to set its items property to my text/images, which made the app crash.

Going through the documentation for the UITabBarController I read this under the tabBar property:

The tab bar view associated with this controller. (read-only)

@property(nonatomic,readonly) UITabBar *tabBar Discussion You should never attempt to manipulate the UITabBar object itself stored in this property. If you attempt to do so, the tab bar view throws an exception. To configure the items for your tab bar interface, you should instead assign one or more custom view controllers to the viewControllers property. The tab bar collects the needed tab bar items from the view controllers you specify.

The tab bar view provided by this property is only for situations where you want to display an action sheet using the showFromTabBar: method of the UIActionSheet class.

This is what I want:

The tab bar collects the needed tab bar items from the view controllers you specify.

It also makes开发者_运维知识库 perfect sense that you do not setup up the tabBar in one place and the content in another.

But how do I define these items in my viewControllers which are all of type UINavigationController, with my custom ViewController as the rootController?

Is there some protocol besides the UITabBarControllerDelegate I need to implement?

Hope someone could point me in the right direction, I did not see this one coming:) Thanks


In general, the tab bar items gets filled with the name of the view controller you are loading into it.

In your case you can do one thing,

[tabbarContrller.tabBarItem initWithTitle:@"rafsfsa" image:[UIImage imageName:@"some.png" tag:0];

Do reply if you get this in.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜