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
Tab bar icon and title not showing with Storyboard References
提问by MXV
回答by Drew C
Here's how to get the tab to show properly:
以下是让选项卡正确显示的方法:
- Put the first UIViewController that will be embedded in the tab in
the same storyboardas the UITabViewController.
- 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.
- Select the content view controller.
- Click the Editor menu and choose Refactor to Storyboard...
- 将第一个嵌入在标签中的 UIViewController 放在与 UITabViewController相同的故事板中。
- Ctrl + 从选项卡栏控制器拖动到内容视图控制器以照常进行连接。这将自动将 UITabBarItem 添加到内容视图控制器的底部。
- 选择内容视图控制器。
- 单击 Editor 菜单并选择 Refactor to Storyboard...
The UITabBarController tab will now point to the new storyboard reference...
... and the content view controller preserves the UITabBarItem from the tab bar relationship. It will appear normally in the app now.
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.
您可以在您所引用的故事板的初始视图控制器中修改选项卡栏项的图像/标题。您只需要向初始视图控制器添加一个“标签栏项目”并相应地更改其属性(标题/图像)。
- Outline view of the root view controller in the referred storyboard
- 引用的故事板中根视图控制器的大纲视图
- 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.
注意:更改不会反映在主故事板的标签栏上;您只能在引用的故事板和运行时看到它。
回答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.
现在运行该应用程序,您现在将看到您的选项卡。
回答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 :
我尝试添加另一个标签栏,然后添加标签栏项目,为它选择和图像但上面的非似乎适用于我的情况..它是这样的:
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 :
后来我发现我的导航项和标签栏项不在一起:
Now its working :):)
现在它的工作:):)
回答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。
回答by Mauricio Chirino
回答by Alexander Khitev
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.
}