xcode 是否可以从标签栏项目执行转场?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31278709/
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
is it possible to perform a segue from tab bar item?
提问by Ayush
I used a UIview controller for my app home page and then added a tab bar at the bottom just like Facebook and then added 3 more tab bar item, it doesn't let me perform a segue when drag the tab bar item to a View Controller, is it possible progmatically or in storyboard?
我为我的应用主页使用了 UIview 控制器,然后像 Facebook 一样在底部添加了一个标签栏,然后又添加了 3 个标签栏项目,当将标签栏项目拖动到视图控制器时,它不会让我执行 segue ,是否有可能以编程方式或故事板?
回答by Luke S
Simple: You need a UITabViewController, tab bar items can't be used the way you're asking for.
简单:您需要一个 UITabViewController,标签栏项目不能按您要求的方式使用。
Ctrl+drag from your tabview controller to a view you'd like to include (Third in this case)
Ctrl+从您的 tabview 控制器拖动到您想要包含的视图(在本例中为第三个)
You then select the view controllersoption to add the relationship segue.
然后选择视图控制器选项以添加关系转场。
回答by Maria Camila Alvarez
I had the same problem, but i couldn't find a way to assign to a viewController its own viewControllers as in the TabViewController case.
我遇到了同样的问题,但我找不到一种方法来将它自己的 viewController 分配给一个 viewController,就像在 TabViewController 的情况下一样。
I solved it using containers.One container for each tabBarItem in your tabBar, which are hidden or showed depending of the selected tabBarItem in the tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
method.
我用容器解决了它。tabBar 中每个 tabBarItem 的一个容器,根据方法中选定的 tabBarItem 隐藏或显示tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
。
1.Create your containers in your UIviewController in storyBoard: Just like this Select your tabBar and Ctrl+Drag to delegate the class for listen the tabBarDelegate methods: look here
1.在 storyBoard 的 UIviewController 中创建容器:就像这样选择你的 tabBar 和 Ctrl+Drag 来委托类来监听 tabBarDelegate 方法:看这里
2.Declare the corrisponging IBOutlets, incliding your tabBAr:
2.声明相应的 IBOutlets,包括您的 tabBAr:
#import <UIKit/UIKit.h>
@interface TabsMainViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@property (strong, nonatomic) IBOutlet UIView *directoryContainer;
@property (strong, nonatomic) IBOutlet UIView *groupsContainer;
@end
3.Select the container to show in the tabBarDelegate method:
3.在tabBarDelegate方法中选择要显示的容器:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch (item.tag) {
case 1:
_directoryContainer.hidden = NO;
_groupsContainer.hidden = YES;
break;
case 2:
_directoryContainer.hidden = YES;
_groupsContainer.hidden = NO;
break;
default:
break;
}
}
Hope that helps!
希望有帮助!