开发者

How to remove badge from specific tab bar after clicking away from it?

I want to remove the badge from the tab bar only after the user clicks away from the tab bar with the badge

For example, the badge appears on the 'News' tab as shown below.

How to remove badge from specific tab bar after clicking away from it?

If I click on the News tab, the badge will still be showing. The badge will only disappear after I click on any 开发者_Go百科other tabs (other than news).

How can I implement this in the app delegate?

EDIT

I tried to set the UITabbardelegate via the following code:

tabController.tabBar.delegate = self;

But I keep getting the following error

Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'

How do I resolve this?


In your case, the 1 badge is located on the index 3 tab, so you would do:

[[tabBar.items objectAtIndex:3] setBadgeValue:nil];

It's up to you to figure out when the user taps on the tab with the badge, you can get that feedback by first assigning a tag to your tabbar items, then use:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{ 
    switch (item.tag) 
    {
        case 3: /* News */
            /* Tabbar item #3 was pressed, do something here. */
            break;
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜