iPhone:无法从 uitabbaritem 读取徽章值
我试图以编程方式确定我的应用程序中的特定选项卡栏项目是否有徽章。
当我在调试时,从视觉上看,我可以清楚地看到它确实如此。但是当我在有问题的 viewController 中运行此代码时:
UITabBarItem* thisVCsTabBarItem = self.tabBarItem;
NSString* badgeValue = thisVCsTabBarItem.badgeValue;
...badgeValue 为零。当我在调试器中检查 thisVCsTabBarItem 时,它的 _badgeValue 成员为零。
这是怎么回事?我应该做一些不同的事情来尝试从选项卡栏项目中读取这个值吗?
谢谢。
I'm trying to figure out programmatically if a particular tab bar item in my app has a badge.
While I'm debugging, visually, I can plainly see that it does. But when I run this code in the viewController in question:
UITabBarItem* thisVCsTabBarItem = self.tabBarItem;
NSString* badgeValue = thisVCsTabBarItem.badgeValue;
...badgeValue is nil. And when I inspect thisVCsTabBarItem in the debugger, its _badgeValue member is nil.
What's going on here? Should I be doing something differently in trying to read this value from the tab bar item?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看一些使用
UITabBarItem
badgeValue
属性的代码,我发现self.tabBarItem.badgeValue
返回nil
而 self.navigationController.tabBarItem.badgeValue 返回正确的值。会是这样吗?问题是,自动完成实际上在
self
之后给了我tabBarItem
。因此很容易犯错误。Looking at some code where I use the
UITabBarItem
badgeValue
property, I see thatself.tabBarItem.badgeValue
returnsnil
whileself.navigationController.tabBarItem.badgeValue
returns the correct value. Could that be it?The thing is that the auto-completion actually gives me
tabBarItem
afterself
. Easy to make a mistake because of that.我对“下载”选项卡执行类似的操作:
我认为您不应该直接访问 tabBarItem。最好在
tabBarController
的 items 数组中找到您的项目。I do something like this for a Downloads tab:
I don't think you are supposed to access the tabBarItem directly. It is better find your item in the
tabBarController
's items array.