UItabbar 项目不显示情节提要参考

UItabbar item not showing storyboard reference

我正在尝试在标签栏中使用新的故事板引用。当我使用故事板参考时,UITabBarItem(带有自定义图像和文本集)没有显示任何内容。查看设置: storyboard setup

tabbaritem setup

我现在通过在 initWithCoder 函数中为引用的情节提要中的初始 viewcontroller 设置图像和标题来修复它,如下所示:

static NSString *const ContactsViewControllerTabContactImageName = @"tab-contact";
static NSString *const ContactsViewControllerTabContactActiveImageName = @"tab-contact-active";

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.title = NSLocalizedString(@"Contacts", nil);
        self.tabBarItem.image = [UIImage imageNamed:ContactsViewControllerTabContactImageName];
        self.tabBarItem.selectedImage = [UIImage imageNamed:ContactsViewControllerTabContactActiveImageName];
    }
    return self;
}

你可以像这样获取故事板参考

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" 捆绑包:无];

参考以下链接

  1. How to change the tab bar image color for selected and unselected

您需要在目标故事板视图控制器中添加标签栏项目。

这个答案很晚,但我遇到了类似的问题。这可能对后来 post 找到此内容的其他人有所帮助。

当使用 UISplitViewController 时,我在 storyboard 中添加项目时遇到 issue这可以通过变通方法解决。

场景:

UITabBarController -> StoryboardReference -> UISplitViewController

问题:

您不能将 UITabBarItem 添加到 UISplitViewController

解决方案/解决方法:

在 UISplitViewControllers 故事板中添加一个 UITabBarController,并将 UISplitViewController 指定为 tabs.An UITabBarItem 之一,将添加到 UISplitViewController。您可以删除不需要的 UITabBarController。 UITabBarItem 将被保留。