Tabbar can't display the image
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:different开发者_高级运维viewcontroller];
[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];
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
精彩评论