在 ViewController 中重新加载/刷新选项卡栏项目?
我正在尝试更改 ViewController 中选项卡栏的图像,但要显示新图像,我必须单击每个选项卡栏项目。
for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
myItem.enabled = YES;
myItem.badgeValue = @"1";
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:@"test.png"]];
*myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}
有人知道如何直接显示这些图像吗? 谢谢
I am trying to change images of my tabbar in a ViewController, but to display the new images, I must click on each tab bar item.
for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
myItem.enabled = YES;
myItem.badgeValue = @"1";
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:@"test.png"]];
*myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}
Anyone know How can I can display directly these images?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个老问题。当我需要从另一个活动选项卡更新徽章值时,我遇到了同样的问题。创建另一个
UITabBarItem
将解决您当前的问题,但在多次调用此代码时会导致潜在的内存泄漏。另外,当其他视图控制器访问该选项卡时,它们不会引用新创建的UITabBarItem
。我的技巧是它对我有用。
I know this is an old question. I ran into the same problem when I need to update the badge value from another active tab. Creating another
UITabBarItem
will solve your current problem but causes potential memory leak when this code is called many times. Plus, when other view controllers access the tab, they do not have reference to newly createdUITabBarItem
. My trick isIt works for me.
您需要用新选项卡栏项目替换旧选项卡栏项目。否则您无法动态更新图像。
最简单的方法是设置给定选项卡表示的视图控制器的 tabBarItem 属性。如果您想从该视图控制器中执行此操作,只需编写:
或者,您可以从其他地方执行此操作,例如您的应用程序委托:
You need to replace the old tab bar item with a new one. You can't update the image dynamically otherwise.
The easiest way to do this is to set the tabBarItem property of the view-controller represented by a given tab. If you wanted to do this from within that view controller, just write:
Or, you could do this from somewhere else, say your app delegate: