没有 TabBarController 的标签栏 - 在故事板中为标签栏项目添加视图控制器 [英] Tab bar without TabBarController - add View Controller for Tab bar item in storyboard

查看:24
本文介绍了没有 TabBarController 的标签栏 - 在故事板中为标签栏项目添加视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向视图控制器添加了一个标签栏(不是 TabViewController),然后向该标签栏添加了一些标签栏项目.

I have added a Tab bar (not a TabViewController) to a View Controller and then added some Tab bar items to that Tab bar.

现在我想将其他视图控制器附加到 Storyboard 中的那些标签栏项.

Now I want to attach other View Controllers to those tab bar items in Storyboard.

当我从选项卡栏项按 Ctrl + 拖动到视图控制器时,我没有任何选项.

When I do Ctrl + Drag to View Controller from tab bar item I do not get any options.

请提出一种方法来做到这一点.

Please suggest a way to do this.

推荐答案

我遇到了同样的问题,但我找不到一种方法,将它自己的 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 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.

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;
        }

    }

希望有帮助!

这篇关于没有 TabBarController 的标签栏 - 在故事板中为标签栏项目添加视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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