xcode 标签栏图标和标题未与 Storyboard References 一起显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35209794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:30:16  来源:igfitidea点击:

Tab bar icon and title not showing with Storyboard References

iosxcodestoryboardios9storyboard-reference

提问by MXV

I have the following storyboard with a segue to a storyboard reference:

我有以下故事板和故事板参考:

enter image description here

在此处输入图片说明

The problem is that when I run the app, it doesn't show the icon or the title:

问题是当我运行应用程序时,它没有显示图标或标题:

enter image description here

在此处输入图片说明

These are the item settings:

这些是项目设置:

enter image description here

在此处输入图片说明

What am I missing?

我错过了什么?

回答by Drew C

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 storyboardas the UITabViewController. enter image description here
  2. Ctrl + Drag from the tab bar controller to the content view controller to make the connection as per usual. This will automatically add the UITabBarItem to the bottom of the content view controller. enter image description here
  3. Select the content view controller.
  4. Click the Editor menu and choose Refactor to Storyboard... enter image description here
  1. 将第一个嵌入在标签中的 UIViewController 放在与 UITabViewController相同的故事板中。 在此处输入图片说明
  2. Ctrl + 从选项卡栏控制器拖动到内容视图控制器以照常进行连接。这将自动将 UITabBarItem 添加到内容视图控制器的底部。 在此处输入图片说明
  3. 选择内容视图控制器。
  4. 单击 Editor 菜单并选择 Refactor to Storyboard... 在此处输入图片说明

The UITabBarController tab will now point to the new storyboard reference... enter image description here... and the content view controller preserves the UITabBarItem from the tab bar relationship. It will appear normally in the app now. enter image description here

UITabBarController 选项卡现在将指向新的故事板引用... 在此处输入图片说明...并且内容视图控制器从选项卡栏关系中保留 UITabBarItem。它现在将正常出现在应用程序中。 在此处输入图片说明

回答by Dries

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. 引用的故事板中根视图控制器的大纲视图

document outline of referred to storyboard

参考故事板的文档大纲

  1. The modified tab bar item in the view controller
  1. 视图控制器中修改后的标签栏项

initial view controller with modified tab bar item

带有修改过的标签栏项目的初始视图控制器

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.

注意:更改不会反映在主故事板的标签栏上;您只能在引用的故事板和运行时看到它。

回答by Bocaxica

The problem is that in the target view controller, you don't have a UITabBarItem in the views hierarchy. The TabBarItem is related to the storyboard reference, but should be related to the View Controller.

问题是在目标视图控制器中,视图层次结构中没有 UITabBarItem。TabBarItem 与 storyboard 引用相关,但应该与 View Controller 相关。

Looks like a "bug" in Xcode...

看起来像 Xcode 中的“错误”...

To resolve this you can do the following:

要解决此问题,您可以执行以下操作:

  • Just create the segues from the UITabBarController to the Storyboard references.
  • 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.
  • 只需创建从 UITabBarController 到 Storyboard 引用的 segue。
  • 您可以在 Storyboard 引用中配置 Tab Bar Items,它们除了在 Storyboard 的 Tab bar 中显示 Tab 之外别无其他,这对开发来说很好。

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
  • 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.

现在运行该应用程序,您现在将看到您的选项卡。

In interface builder, find the Tab Bar item in the Object Library

在界面生成器中,找到对象库中的 Tab Bar 项

Drag the Tab Bar item into your the destination view controller by following the storyboard reference

按照情节提要参考将 Tab Bar 项拖到目标视图控制器中

回答by Parajuli Roman

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 : Other VC tabs were showing tabBar icons properly but one that i refactored was missing its icon

我尝试添加另一个标签栏,然后添加标签栏项目,为它选择和图像但上面的非似乎适用于我的情况..它是这样的: 其他 VC 选项卡可以正确显示 tabBar 图标,但我重构的选项卡缺少图标

Then i compared it with VC that were working properly with TabBar icons.. enter image description here

然后我将它与使用 TabBar 图标正常工作的 VC 进行了比较。 在此处输入图片说明

later i found that my navigation items and tab bar items were not together :

后来我发现我的导航项和标签栏项不在一起:

The Tab bar item was inside with Navigation Bar.... i dragged the tabBar item to HomeVC and placed with NavigationBar item

The Tab bar item was inside with Navigation Bar.... i dragged the tabBar item to HomeVC and placed with NavigationBar item

Now its working :):)

现在它的工作:):)

enter image description here

enter image description here

回答by QuattroDog

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

场景导航器

回答by Mauricio Chirino

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 imagebar item section inside the storyboard's reference like shown in the attached image:

我遇到了完全相同的问题,上述答案都不适用于我的情况。我通过在故事板参考中的图像栏项目部分设置我的标签栏图像来解决,如附图所示:



enter image description here

enter image description here

回答by Alexander Khitev

I made following in the storyboard and made class for each UINavigationControllerand made following code in each UINavigationControllerclass

我在故事板中关注并为每个课程制作课程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.
    }

enter image description here

enter image description here