升级到Xcode 7后,UITabbar项目直到点击才显示

7
我有一个UITabBar,在升级到Xcode 7之前正常运行,但现在我找不出问题所在。我尝试了几种解决方案,包括为我创建的每个选项卡设置imageWithRenderingMode,尝试更改UITabBar的背景颜色以查看是否仅仅是选项卡是白色的,以及将图标本身更新为新版本。我的默认选中选项卡完全正常显示,当我选择另一个选项卡时,文本会显示出来,但是没有图像。(文本也会保持,并且在移动到另一个选项卡时更改为默认的灰色。)
以下是我目前实现选项卡栏的方式。 创建选项卡栏的函数:
void MakeTabBar(id target)
{
    PFUser *currentUser = [PFUser currentUser];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.recentView = [[RecentView alloc] init];
    appDelegate.groupsView = [[GroupsView alloc] init];
    appDelegate.settingsView = [[SettingsView alloc] init];
    appDelegate.homeView = [[HomeView alloc] init];

    NavigationController *navController1 = [[NavigationController alloc] initWithRootViewController:appDelegate.recentView];
    NavigationController *navController2 = [[NavigationController alloc] initWithRootViewController:appDelegate.groupsView];
    NavigationController *navController4 = [[NavigationController alloc] initWithRootViewController:appDelegate.settingsView];
    NavigationController *navController5 = [[NavigationController alloc] initWithRootViewController:appDelegate.homeView];

    appDelegate.tabBarController = [[UITabBarController alloc] init];
    appDelegate.tabBarController.tabBar.translucent = NO;
    appDelegate.tabBarController.selectedIndex = DEFAULT_TAB;
    [[UITabBar appearance] setTintColor:COLOR_OUTGOING];

    NSMutableDictionary *customAttributes = [NSMutableDictionary dictionary];
    BOOL isAdmin = [currentUser[@"isAdmin"] boolValue];
    if(isAdmin){
        [customAttributes setObject:currentUser[@"isAdmin"] forKey:@"isAdmin"];
        appDelegate.peopleView = [[PeopleView alloc] init];
        NavigationController *navController3 = [[NavigationController alloc] initWithRootViewController:appDelegate.peopleView];
        appDelegate.tabBarController.viewControllers = @[navController5, navController1, navController2, navController3, navController4];
    } else{
        appDelegate.tabBarController.viewControllers = @[navController5, navController1, navController2, navController4];
    }

    BOOL isTester = [currentUser[@"isTestData"] boolValue];
    if(isTester){
        [customAttributes setObject:currentUser[@"isTestData"] forKey:@"isTestData"];
    }

    [appDelegate.window setRootViewController:appDelegate.tabBarController];
}

在每个视图中编写代码以创建选项卡:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    {
        [self.tabBarItem setImage:[UIImage imageNamed:@"tab_consultants"]];
        self.tabBarItem.title = @"Consultants";
    }
    return self;
}

enter image description here

3个回答

8

经过多次尝试,我发现问题是由于导航控制器和我的选项卡栏包含在我的UINavigation中,而UINavigation的颜色与顶部导航栏不同。我将它们分开处理,现在它按预期工作。


4

1

我也遇到了同样的问题。我通过编写以下代码解决了它。

let storyboard   = UIStoryboard.init(name: "Main", bundle: Bundle.main)
let vc1          = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
vc1.tabBarItem   = ESTabBarItem.init(ExampleIrregularityBasicContentView(), title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))

希望它能对你有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接