开发者

How to change TabBarItem image and title-issue

I'm working with tabBar Based application wi开发者_如何转开发th navigation controller. In my application I want to change the tabBarItem image and title. At the time of clicking the pariticular tabBarItem the control goes to viewWillAppear method of that particular view. In this time i want to change image and title of that particular tabBarItem.

I'm giving like this but,it's not working...

Code:

tabItem = [[UITabBarItem alloc] initWithTitle:@"Colors" image:[UIImage imageNamed:@"Colors.png"] tag:9];

self.tabBarController.tabBarItem = tabItem;

Already I'm setting the tag value for that view is 9.

Please help me how can I change the image and title of that particular tabbarItem .


There is a slight misconception in what you are attempting to do. First of all, UITabBarController has no tabBarItem property, which is what you are attempting to set. But, even if it did, the UITabBarController docs specifically state, in regards to UITabBarController's tabBar property:

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.

So, the way to modify the items is not through the UITabBar itself. In your situation, the UITabBar is getting its UITabBarItems from the UIViewControllers represented by each tab. This is something you have control over. Specifically, what you can do is:

- (void)viewWillAppear:(BOOL)animated {
    /* Modifies the UITabBarItem used by a UITabBarController to represent this
     * UIViewController in the tab bar.
     */

    UITabBarItem* tabBarItem =  [[UITabBarItem alloc] initWithTitle:@"Colors" image:[UIImage imageNamed:@"Colors.png"] tag:9];
    self.tabBarItem = tabBarItem;
    [tabBarItem release];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜