如何在用户单击另一个选项卡后删除 UITabBar 徽章?
我想在用户单击另一个选项卡后立即删除徽章。我正在尝试这样做:
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
UITabBarItem *tbi = (UITabBarItem *)self.tabController.selectedViewController.tabBarItem;
tbi.badgeValue = nil;
}
但它不起作用。
I want to remove a badge as soon as the user clicks another tab. I am trying to do:
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
UITabBarItem *tbi = (UITabBarItem *)self.tabController.selectedViewController.tabBarItem;
tbi.badgeValue = nil;
}
But it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想从当前选项卡或触摸的选项卡中删除徽章吗?
无论哪种方式,执行此操作的正确位置是在选项卡栏控制器委托中:
请注意,每当用户点击选项卡栏按钮时都会调用此函数,无论显示的新视图控制器是否与旧视图控制器不同,因此您需要跟踪当前的可见视图控制器。您也可以在此处更新:
You want to remove a badge from the current tab, or the one touched?
The right place to do this, either way, is in your tab bar controller delegate, in:
Note that this function gets called whenever the user taps on a tab bar button, regardless of whether the new view controller shown is different from the old one, so you'll want to track your current visible view controller. This is where you'll update that, too: