从 UIView 更新 UITabBarController 的徽章值的最佳方法 [英] Best way to update badgeValue of UITabBarController from a UIView

查看:18
本文介绍了从 UIView 更新 UITabBarController 的徽章值的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 AppDelegate 中设置了一个 tabBarController,并且有几个带有导航控制器的 UIViewController.在其中一个 TabBar 项中,在我推送了几个 UIView 之后,我想更新另一个 TabBar 项的徽章值项.

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 的徽章值的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆