tabbar无法显示图片
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先 - 在这段代码中,您泄漏了 viewControllersArray 和 uitabbarcontroller
我认为图像名称或未添加到构建目标的图像名称存在问题。
查找未在项目导航器中显示的文件,并在目标成员身份中选中目标的复选框
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