views:

109

answers:

1

Hi

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

+1  A: 

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....

Hi Thanks...I do feel a bit stupid, I started to build the ViewControllers and when I did [self.navigationController setTitle:@"String"] the title turn up on the button. I then did [self.navigationController setTabBarItem:myItem] ... the methods were there, just as the documentation said, I was just focusing on the TabBarController.Thanks again.
RickiG