问题描述
我在AppDelegate中设置了tabBarController,并且有一些带有Nav Controllers的UIViewControllers。在其中一个TabBar项目中,在我推动了几个UIViews后,我想更新另一个TabBar项目的badgeValue项目。
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.
最好的方法是什么?我能够真正想到的唯一方法是NSNotification和单值存储的价值,但似乎很多简单的工作,我不知道NSNotifications。
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.
我对super.tabBarController.otherView.tabBarItem.badgeValue = @1这样的东西进行了疯狂猜测(因为我设置了以类似的方式选择了哪个选项卡)但我并不感到惊讶,这不起作用。
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.
谢谢
推荐答案
感谢alku83指出我正确的方向,代码是:
Thanks to alku83 who pointed me in the right direction the code is:
[[super.tabBarController.viewControllers objectAtIndex:2] tabBarItem].badgeValue = @"1";
这篇关于从UIView更新UITabBarController的badgeValue的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!