2016-08-03 124 views
-4

这是问题: UITabBarController有时会出现错误,点击一些tabbarItem会正确,或者等待几秒钟恢复正常。这是怎么回事?为什么这个tabbar显示错误?

这是代码

-(UITabBarController*)getTabViewController 
{ 
    //创建TabbarController 
    self.tabBarVc = [[UITabBarController alloc] init]; 
    self.tabBarVc.delegate = self; 
    UITabBarItem *leftItem = [[UITabBarItem alloc] initWithTitle:@"积分兑换" image:[UIImage imageNamed:@"jifenduihuan"] selectedImage:[UIImage imageNamed:@"jifenduihuanblue"]]; 
UITabBarItem *centerItem = [[UITabBarItem alloc] initWithTitle:@"品牌商户" image:[UIImage imageNamed:@"jifenshanghu"] selectedImage:[UIImage imageNamed:@"jifenshanghublue"]]; 
UITabBarItem *newsItem = [[UITabBarItem alloc] initWithTitle:@"积分资讯" image:[UIImage imageNamed:@"new"] selectedImage:[UIImage imageNamed:@"new2"]]; 
UITabBarItem *rightItem = [[UITabBarItem alloc] initWithTitle:@"个人中心" image:[UIImage imageNamed:@"gerenzhongxin"] selectedImage:[UIImage imageNamed:@"gerenzhongxinblue"]]; 
UIOffset titleOffset=UIOffsetMake(0, -5); 
    UIOffset titleOffset=UIOffsetMake(0, -5); 
    [leftItem setTitlePositionAdjustment:titleOffset]; 
    [centerItem setTitlePositionAdjustment:titleOffset]; 
    [rightItem setTitlePositionAdjustment:titleOffset]; 
    [newsItem setTitlePositionAdjustment:titleOffset]; 
    //homeNav,shopNav,myInfoNav and newsNav is UINavigationController 
    [HomeNav setTabBarItem:leftItem]; 
    [shopNav setTabBarItem:centerItem]; 
    [myInfoNav setTabBarItem:rightItem]; 
    [newsNav setTabBarItem:newsItem]; 

    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 49)]; 
    backView.backgroundColor = [UIColor whiteColor]; 
    [self.tabBarVc.tabBar insertSubview:backView atIndex:0]; 
    self.tabBarVc.tabBar.opaque = YES; 
    [self.tabBarVc.tabBar setTintColor:MainColor]; 
    self.tabBarVc.viewControllers = [NSArray arrayWithObjects:HomeNav,shopNav,newsNav,myinfoNav,nil]; 


    return self.tabBarVc; 
} 

this is screenshot

+0

发布您的代码PLZ。 – Catoshi

+0

它可能是导致问题的tabbaritem图像大小。反正请把代码放在眼里,让我们看看并为您提供解决方案。 – ManiaChamp

+0

@TonyHan发布 – DanielXu

回答

0

试试这个:

//homeNav,shopNav,myInfoNav and newsNav is UINavigationController 
[HomeNav setTabBarItem:leftItem]; 
[shopNav setTabBarItem:centerItem]; 
[myInfoNav setTabBarItem:rightItem]; 
[newsNav setTabBarItem:newsItem]; 
[HomeNav.tabBarItem setTitlePositionAdjustment:titleOffset]; 
[centerItem.tabBarItem setTitlePositionAdjustment:titleOffset]; 
[rightItem.tabBarItem setTitlePositionAdjustment:titleOffset]; 
[newsItem.tabBarItem setTitlePositionAdjustment:titleOffset];