开发者

Change title of UITabBarItem dynamically

I have 9 tabs in my tabbar... And I开发者_高级运维 want to change the title of all of them from some view controller. and I did it as follows:

for (int i=0; i(less than)[appDelegate.tabBarController.viewControllers count]; i++) {
  UIViewController *uv=[appDelegate.tabBarController.viewControllers objectAtIndex:i];
  uv.tabBarItem.title=@"test";
}

It changes the title for all visible tabs instantly but not working for tabs in more...

However if I click on edit button in more nav cntrl it shows changed name. Also... very strange... If I select some tab in more then all the tabs reflects new name

why is it so???


Changing the title of a UIBarItem (superclass of UITabBarItem) needs to be done before the item is added to a bar per Apple docs. Looks like iOS is caching the titles once the items are added to the bar so you're getting unpredictable behavior.

From the UIBarItem Class Reference:

title
The title displayed on the item.

@property(nonatomic, copy) NSString *title

Discussion
You should set this property before adding the item to a bar. The default value is nil.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜