[英]Tab bar icon and title not showing with Storyboard References
Here's how to get the tab to show properly: 以下是如何正确显示标签:
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. 您只需要向初始视图控制器添加“标签栏项”并相应地更改其属性(标题/图像)。
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: 要解决此问题,您可以执行以下操作:
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: 要使标签显示在正在运行的应用程序中,请执行以下操作:
Now run the app and you will now see your tabs. 现在运行应用程序,您现在将看到您的选项卡。
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 :):) 现在它的工作:) :)
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。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.