从 UIView 更新 UITabBarController 的 badgeValue 的最佳方法
我在 AppDelegate 中设置了一个 tabBarController,并有一些带有导航控制器的 UIViewController。在其中一个 TabBar 项目中,在推送了几个 UIView 后,我想更新另一个 TabBar 项目的 badgeValue 项目。
最好的方法是什么?我真正能想到的唯一方法是 NSNotification 和值的单例存储,但对于简单的事情来说似乎需要做很多工作,而且我对 NSNotifications 一无所知。
我对像 super.tabBarController.otherView.tabBarItem.badgeValue = @"1" 这样的东西有一个疯狂的猜测(因为我设置以类似的方式选择哪个选项卡),但我并不感到惊讶这不起作用。
谢谢
I have a tabBarController set up in the AppDelegate and have a few UIViewControllers with Nav Controllers. In one of the TabBar items, after I have pushed a few UIViews I want to update the badgeValue item of a different TabBar item.
Whats the best way to do this? The only way I can really think is a NSNotification and a singleton storage for the value, but it seems a lot of work for something simple, that and I have no idea about NSNotifications.
I had a wild guess at something like super.tabBarController.otherView.tabBarItem.badgeValue = @"1" (as I set which tab is selected in a similar way) but I'm not surprised this doesn't work.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢 alku83 为我指明了正确的方向,代码是:
Thanks to alku83 who pointed me in the right direction the code is:
我正在使用 Xcode 4.5 和 Storyboards 和 iOS 6,所以答案自最初发布以来可能已经改变。
首先,您必须像这样访问选项卡栏控制器:
然后您可以像这样设置徽章:
I'm using Xcode 4.5 with Storyboards and iOS 6, so the answer may have changed since it was originally posted.
First you have to access the Tab Bar Controller like this:
Then you can set the badge like so:
我现在手头没有代码,但它应该更像是
I don't have the code on hand right now, but it should be something more like