tabbar无法显示图片

发布于 2024-12-10 04:51:59 字数 1439 浏览 0 评论 0原文

在我的 uiviewcontroller 子类中,实现委托方法 UITabBarControllerDelegate。我的init方法是这样的:

- (void)viewDidLoad
{
    [super viewDidLoad]; 
    NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
    [viewControllersArray addObject:Originalviewcontroller];
    [viewControllersArray addObject:differentviewcontroller];
    [viewControllersArray addObject:tradeviewcontroller];
    UITabBarController *uitabbarcontroller = [[UITabBarController alloc]init];
    uitabbarcontroller.delegate = self;
    uitabbarcontroller.viewControllers = viewControllersArray;
    [_shanghaitradeviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"OriginalMarket.png"] tag:1];
    [_shanghaidifferentviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"DifferentMarket.png"] tag:2];
    [_shanghaitradeviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"Trade.png"] tag:3];
    [self.view addSubview:uitabbarcontroller.view];
}

一切看起来都很正常,但是第一张图片无法显示,为什么?

更新
很抱歉,我找到了答案,因为我犯了一个错误:

[_shanghaitradeviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"OriginalMarket.png"] tag:1];

并且应该是:

_shanghaiOriginalviewcontroller = [[ShanghaiOriginalMarketViewController alloc]initWithNibName:@"ShanghaiOriginalMarketViewController" bundle:nil];

In my a subclass of uiviewcontroller, implement the delegate method UITabBarControllerDelegate. My init method like:

- (void)viewDidLoad
{
    [super viewDidLoad]; 
    NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
    [viewControllersArray addObject:Originalviewcontroller];
    [viewControllersArray addObject:differentviewcontroller];
    [viewControllersArray addObject:tradeviewcontroller];
    UITabBarController *uitabbarcontroller = [[UITabBarController alloc]init];
    uitabbarcontroller.delegate = self;
    uitabbarcontroller.viewControllers = viewControllersArray;
    [_shanghaitradeviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"OriginalMarket.png"] tag:1];
    [_shanghaidifferentviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"DifferentMarket.png"] tag:2];
    [_shanghaitradeviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"Trade.png"] tag:3];
    [self.view addSubview:uitabbarcontroller.view];
}

Everything seems normal, but the first image can't display, why?

UPDATE:
So sorry, I found the answer because I make a mistake:

[_shanghaitradeviewcontroller.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"OriginalMarket.png"] tag:1];

And should be:

_shanghaiOriginalviewcontroller = [[ShanghaiOriginalMarketViewController alloc]initWithNibName:@"ShanghaiOriginalMarketViewController" bundle:nil];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧 2024-12-17 04:51:59

首先 - 在这段代码中,您泄漏了 viewControllersArrayuitabbarcontroller

我认为图像名称或未添加到构建目标的图像名称存在问题。
查找未在项目导航器中显示的文件,并在目标成员身份中选中目标的复选框

First of all - in this code you leaking viewControllersArray and uitabbarcontroller

I think problem in the name of the image or image not added to the build target.
Find file than not displaying in project navigator and in Target membership set checkbox of your target checked

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文