是否可以从标签栏项目执行转场?
我为我的应用主页使用了 UIview 控制器,然后像 Facebook 一样在底部添加了一个标签栏,然后又添加了 3 个标签栏项目,当将标签栏项目拖动到视图控制器,是否可以通过编程或故事板?
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?
我遇到了同样的问题,但我找不到一种方法,将它自己的 viewController 分配给一个 viewController,就像在 TabViewController 的情况下一样.
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.
我使用容器解决了这个问题. tabBar 中的每个 tabBarItem 都有一个容器,根据 tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
方法.
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.
1. 在 storyBoard 的 UIviewController 中创建容器:就像这样选择你的 tabBar 和 Ctrl+Drag 来委托类来监听 tabBarDelegate 方法:看这里
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
2. 声明相应的 IBOutlets,包括您的 tabBAr:
2. Declare the corrisponging IBOutlets, incliding your 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. 选择要在 tabBarDelegate 方法中显示的容器:
3. Select the container to show in the tabBarDelegate method:
-(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;
}
}
希望有帮助!