简体   繁体   English

标签栏图标和标题未显示 Storyboard

[英]Tab bar icon and title not showing with Storyboard References

I have the following storyboard with a segue to a storyboard reference:我有以下 storyboard 和 storyboard 参考:

在此处输入图像描述

The problem is that when I run the app, it doesn't show the icon or the title:问题是当我运行应用程序时,它不显示图标或标题:

在此处输入图像描述

These are the item settings:这些是项目设置:

在此处输入图像描述

What am I missing?我错过了什么?

Here's how to get the tab to show properly: 以下是如何正确显示标签:

  1. Put the first UIViewController that will be embedded in the tab in the same storyboard as the UITabViewController. 将第一个将嵌入到选项卡中的UIViewController放在与UITabViewController 相同的故事板中。 在此输入图像描述
  2. Ctrl + Drag from the tab bar controller to the content view controller to make the connection as per usual. Ctrl +从标签栏控制器拖动到内容视图控制器以按照惯例进行连接。 This will automatically add the UITabBarItem to the bottom of the content view controller. 这将自动将UITabBarItem添加到内容视图控制器的底部。 在此输入图像描述
  3. Select the content view controller. 选择内容视图控制器。
  4. Click the Editor menu and choose Refactor to Storyboard... 单击Editor菜单,然后选择Refactor to Storyboard ... 在此输入图像描述

The UITabBarController tab will now point to the new storyboard reference... UITabBarController选项卡现在将指向新的故事板参考... 在此输入图像描述 ... and the content view controller preserves the UITabBarItem from the tab bar relationship. ...并且内容视图控制器从标签栏关系中保留UITabBarItem。 It will appear normally in the app now. 它现在通常会在应用程序中显示。 在此输入图像描述

You can modify image/title of the tab bar item in the initial view controller of the storyboard you are referring to. 您可以在所引用的故事板的初始视图控制器中修改选项卡栏项的图像/标题。 You just need to add a 'tab bar item' to the initial view controller and change its properties (title/image) accordingly. 您只需要向初始视图控制器添加“标签栏项”并相应地更改其属性(标题/图像)。

  1. Outline view of the root view controller in the referred storyboard 在引用的故事板中概述根视图控制器的视图

提到故事板的文件大纲

  1. The modified tab bar item in the view controller 视图控制器中已修改的选项卡栏项

初始视图控制器与修改的标签栏项目

Note: the change will not be reflected on the tab bar in the main storyboard; 注意:更改不会反映在主故事板中的选项卡栏上; you only see it in the referred storyboard and at runtime. 您只能在引用的故事板和运行时看到它。

The problem is that in the target view controller, you don't have a UITabBarItem in the views hierarchy. 问题是在目标视图控制器中,视图层次结构中没有UITabBarItem。 The TabBarItem is related to the storyboard reference, but should be related to the View Controller. TabBarItem与故事板引用相关,但应与View Controller相关。

Looks like a "bug" in Xcode... 看起来像Xcode中的“bug”......

To resolve this you can do the following: 要解决此问题,您可以执行以下操作:

  • Just create the segues from the UITabBarController to the Storyboard references. 只需从UITabBarController创建segues到Storyboard引用。
  • You may configure the Tab Bar Items in the storyboard references, they don't do much more other than showing the tabs in the tab bar on the Storyboard, which is nice for development purposes. 您可以在故事板引用中配置选项卡栏项目,除了在故事板上的选项卡栏中显示选项卡之外,它们不会做太多其他事情,这对于开发目的很有用。

If you now run the app, you will indeed notice that the tabs are missing. 如果您现在运行该应用程序,您确实会注意到缺少选项卡。 To get the tabs to display in the running app as well, do this: 要使标签显示在正在运行的应用程序中,请执行以下操作:

  • Go to the viewcontroller the storyboard reference is referencing to 转到storyboard引用引用的viewcontroller
  • Add a Tab Bar Item into this View Controller by dragging it from the Object Library into the View Controller 通过将标签栏项目从对象库拖动到视图控制器中,将其添加到此视图控制器中
  • You will now see a tab bar with one single tab in the view controller 现在,您将在视图控制器中看到一个带有一个选项卡的选项卡栏
  • Configure the tab bar item to show the correct title and icon 配置选项卡栏项以显示正确的标题和图标

Now run the app and you will now see your tabs. 现在运行应用程序,您现在将看到您的选项卡。

在界面构建器中,找到对象库中的选项卡栏项

按照故事板引用将Tab Bar项拖动到目标视图控制器中

I tried adding another tab bar, then added tab bar item, selected and image for it BUT Non of above seemed to work with my case .. it was like this : 我尝试添加另一个标签栏,然后添加标签栏项目,选择和图像为它但上面的非上述似乎适用于我的情况..它是这样的: 其他VC选项卡正确显示tabBar图标,但我重构的一个图标缺少其图标

Then i compared it with VC that were working properly with TabBar icons.. 然后我将它与使用TabBar图标正常工作的VC进行了比较。 在此输入图像描述

later i found that my navigation items and tab bar items were not together : 后来我发现我的导航项和标签栏项不在一起:

Tab栏项目位于导航栏内....我将tabBar项目拖动到HomeVC并放置了NavigationBar项目

Now its working :):) 现在它的工作:) :)

在此输入图像描述

After struggling with this problem for a few days I found this solution. 经过几天努力解决这个问题后,我找到了这个解决方案。 Double click the storyboard link, which will open the referenced storyboard. 双击故事板链接,这将打开引用的故事板。 In the scene navigator, you can edit the bar item with a custom title and icon. 在场景导航器中,您可以使用自定义标题和图标编辑条形项。 Works in xCode 9. 适用于xCode 9。

Storyboard 故事板

Scene Navigator 场景导航器

I had this exact same issue and neither of the above answers worked in my case. 我有完全相同的问题,上述答案都不适用于我的情况。 I solved by setting my tab bar image in the image bar item section inside the storyboard's reference like shown in the attached image: 我通过在故事板的参考内的图像栏项目部分设置我的标签栏图像来解决,如附图所示:


在此输入图像描述

I made following in the storyboard and made class for each UINavigationController and made following code in each UINavigationController class 我在故事板中做了以下内容并为每个UINavigationController了类,并在每个UINavigationController类中创建了以下代码

override func viewDidLoad() {
        super.viewDidLoad()
        let someController = StoryboardManager.surveyStoryboard.instantiateViewControllerWithIdentifier("SomeController") as! SomeController
        viewControllers = [someController]
        // Do any additional setup after loading the view.
    }

在此输入图像描述

I did it in different way.我以不同的方式做到了。 My fourth tab was not showing.我的第四个标签没有显示。 I just programmatically placed image on its place.我只是以编程方式将图像放置在它的位置。 You need to set its X,Y coordinates accordingly.您需要相应地设置其 X、Y 坐标。

    let imageName = "video"
    let image = UIImage(named: imageName)
    let imageView = UIImageView(image: image!)
    imageView.frame = CGRect(x: view.frame.width - 80, y:  view.frame.height-70, width: 50, height: 50)
    view.addSubview(imageView)

在此处输入图片说明

Just add a Tab Bar Item in the "child" view controller:只需在“子”视图 controller 中添加一个 Tab Bar Item:

在此处输入图像描述

this works for me这对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM