UITabbar 项目在升级到 Xcode 7 后单击后才会显示

UITabbar items not showing until click following upgrade to Xcode 7

我有一个 UITabBar 在我升级到 Xcode 7 之前运行良好,现在我无法弄清楚我的生活发生了什么。我尝试了几种解决方案,包括为我创建的每个选项卡设置 imageWithRenderingMode,尝试更改 UITabBar 的背景颜色以查看项目是否只是白色,以及将图标本身更新为新的版本。我的默认 selected 选项卡显示得很好,然后当我 select 另一个选项卡时,文本显示,但没有图像。 (移动到另一个选项卡时,文本仍然存在并更改为默认灰色。)

我附上了我所看到的屏幕截图,这是我目前实现标签栏的方式。

创建标签栏的函数:

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;
}

经过大量试验和错误后,我发现问题出在导航控制器上,并且我的标签栏包含在我的 UINavigation 中,它的颜色不同以支持顶部导航栏。我将它们分开,现在它按预期工作了。

我遇到了同样的问题,通过在初始化函数中设置显示的视图控制器的标题解决了这个问题:https://whosebug.com/a/4417666/3647974

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

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"))

希望对您有所帮助