移动到另一个视图时标签栏控制器消失(iOS SDK,使用故事板) [英] Tab Bar controller disappearing when moving to another view (iOS SDK, Using storyboards)

查看:85
本文介绍了移动到另一个视图时标签栏控制器消失(iOS SDK,使用故事板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用故事板构建iPhone应用程序,我的标签栏控制器有问题。在其中一个从选项卡栏控制器(view1)链接的视图中,有一个通向另一个视图(view2)的按钮。在View2上,有一个按钮可以返回View1。很直接。但是当我从view1转到view2时,标签栏消失了,更糟糕的是,当我回到View1时,标签栏仍然消失...
我该如何解决? (我还没有在应用程序中添加任何代码,只有故事板和苹果提供AppDelegate类(我想也是一个主文件,但我不打算接触它)。

I am building an iPhone app using storyboards and I have a problem with the tab bar controller. On one of the views that is linked from the tab bar controller (view1), there is a button that leads to another view (view2). On View2, there is a button that leads back to View1. Very straight forward. But when I go from view1 to view2, the tab bar disappears, and even worse, when I go back to View1, the tab bar is still gone... How can I fix that? (I have yet to put ANY code in the app, there is only the storyboard and the apple provided AppDelegate Class (and also a main file I suppose, but I am not intending on touching that).

非常感谢任何回复!

推荐答案

如果你从一个视图中做一个模态segue标签栏视图,它将摆脱您正在呈现的模态视图的标签栏。

If you do a modal segue from a view that is a tab bar view, it will get rid of the tab bar for the modal view you are presenting.

其次,当您设置视图时,您正在创建视图控制器的新实例所以我猜你是从view1到view2并且丢失了标签栏,然后你又回到了view1。此时你已经创建了view1,view2和没有标签栏的view1的第二个副本。

Secondly, when you segue you are creating a new instance of the view controller. So I am guessing you are segueing from view1 to view2 and losing the tab bar, then you are segueing back to view1. At this point you have created view1, view2, and a second copy of view1 that does not have a tab bar.

我会建议两件事之一。

1。)如果你想保留标签从view1到view2的底部,然后单击view1,在屏幕顶部选择Editor / Embed In / Navigation Controller。这会将您的view1嵌入导航控制器中。然后,如果您将segue从Modal更改为Push,它将使标签栏保持在底部。顶部的导航栏还可以轻松地从视图2返回到视图1以正确的方式(通过弹出视图)而不是创建新的segue。如果您不喜欢导航栏,则可以在检查器中将顶栏属性更改为无。然后,您需要在view2中创建一些其他方法以返回view1。 (通过弹出控制器,而不是通过分割)

1.) If you want to keep the tabs at the bottom when you segue from view1 to view2, then click on view1, at the top of the screen select Editor/Embed In/ Navigation Controller. This will embed your view1 in a navigation controller. Then if you change your segue from Modal to Push it will keep your tab bars at the bottom. The navigation bar at the top also make it easy to go back from view 2 to view 1 the correct way (by popping the view) rather than creating a new segue. If you do not like the navigation bar, then you can change the "Top Bar" property to "None" in the inspector. You will then need to create some other way in view2 to get back to view1. (BY POPPING THE CONTROLLER, NOT BY SEGUEING)

2)如果你不想设置导航控制器,那么保留标签会有点困难在view2控制器底部的条形图。事实上,我不确定你是否可以使用模态segue完成它,你可能不得不写一些类型的自定义segue。无论哪种方式,如果你想转换回view1并转到正确的控制器(不是没有选项卡的新版本),那么你需要将一个动作附加到用于segue的任何按钮并使用以下代码(我也附上)导航控制器推送segue的代码,以防您创建导航控制器并摆脱导航栏。)

2) If you don't want to set up a navigation controller you will have a little bit harder time keeping the tab bar stuff at the bottom of the view2 controller. In fact, I'm not sure you can do it at all with a modal segue, you'd probably have to write some type of custom segue. Either way, If you want to transition back to view1 and get to the correct controller (not a new version without the tabs) then you need to attach an action to whatever button you are using to segue and use the following code (I also attached the code for navigation controller push segues, in case you create a navigation controller and get rid of the navigation bar.)

对于Modal Segue:

For Modal Segue:

[self dismissModalViewControllerAnimated:YES];

对于Push segue:

For Push segue:

[self.navigationController popViewControllerAnimated:YES];

您最好的选择是使用导航控制器方法,因为您可以放心使用。然后你可以使用导航栏返回(简单的方法,不需要代码),或者你可以摆脱它并使用上面的代码按钮。

Your best bet is to use the navigation controller method, as you are assured to keep your tabs. You can then either use the navigation bar to return (the easy way, no code needed) or you can get rid of it and use a button and the code above.

祝你好运!

这篇关于移动到另一个视图时标签栏控制器消失(iOS SDK,使用故事板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆