这是个问题: UITabBarController有时会出现错误,点击一些tabbarItem会正确,或者等几秒钟才能恢复正常。
这是代码
-(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;
}
答案 0 :(得分: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];