[英]Tab bar without TabBarController - add View Controller for Tab bar item in storyboard
I have added a Tab bar (not a TabViewController) to a View Controller and then added some Tab bar items to that Tab bar.我已经向视图控制器添加了一个标签栏(不是 TabViewController),然后向该标签栏添加了一些标签栏项目。
Now I want to attach other View Controllers to those tab bar items in Storyboard.现在我想将其他视图控制器附加到 Storyboard 中的那些标签栏项目。
When I do Ctrl + Drag to View Controller from tab bar item I do not get any options.当我从选项卡栏项按 Ctrl + 拖动到视图控制器时,我没有任何选项。
Please suggest a way to do this.请提出一种方法来做到这一点。
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 contarner 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 的一个容器,根据
tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
方法中选定的 tabBarItem 隐藏或显示它们。
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!希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.