gpt4 book ai didi

iphone - 在 ViewController 中重新加载/刷新选项卡栏项目?

转载 作者:行者123 更新时间:2023-12-03 19:14:48 24 4
gpt4 key购买 nike

我正在尝试更改 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
}

有人知道如何直接显示这些图像吗?谢谢

最佳答案

您需要用新选项卡栏项目替换旧选项卡栏项目。否则您无法动态更新图像。

最简单的方法是设置给定选项卡表示的 View Controller 的 tabBarItem 属性。如果您想从该 View Controller 中执行此操作,只需编写:

self.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image: myImage: tag: nil];

或者,您可以从其他地方执行此操作,例如您的应用程序委托(delegate):

UIViewController* vc = [tabBarController.viewControllers objectAtIndex: 3];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image: myImage: tag: nil];

关于iphone - 在 ViewController 中重新加载/刷新选项卡栏项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4216179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com