简体   繁体   English

iOS创建没有情节提要的TabController

[英]iOS Create TabController without storyboard

maybe stupid, but i'm in confuse, cant find any example creating UITabBarController without storyboard. 也许是愚蠢的,但我感到困惑,找不到没有情节提要创建UITabBarController的任何示例。

I have simply single view application. 我只有单视图应用程序。 And then i press button i want presentViewController which is UITabBarController 然后我按下按钮,我想要presentITController是UITabBarController

My xib UITabBarController looks like 我的xib UITabBarController看起来像 在此处输入图片说明

as u can see i have two TabBarItems, but then i run it's on simulator i got this picture 如你所见,我有两个TabBarItems,但是随后我在模拟器上运行了这张照片

在此处输入图片说明

Here interface of My tab bar controller 我的标签栏控制器的此处界面

@interface TabsViewController : UITabBarController

and i show its 我展示它

 TabsViewController *tb = [[TabsViewController alloc] initWithNibName:@"TabsViewController" bundle:nil];
        [self presentViewController:tb animated:YES completion:nil];

Also i don't want create it's by code, i want use xib. 我也不想通过代码创建它,我想使用xib。

In your .h ViewController file import the tab menu: 在.h ViewController文件中,导入选项卡菜单:

#import “TabMenu”
@interface firstVC : UIViewController
{
    TabMenu *customView;
}

In your .m ViewController file: 在您的.m ViewController文件中:

- (void)viewDidLoad
{
    customView = [TabMenu tabMenu];

    [customView setFrame:CGRectMake(-customView.frame.size.width, customView.frame.origin.y, customView.frame.size.width, customView.frame.size.height)];
    [self.view addSubview:customView];

    [super viewDidLoad];
}

In your TabMenu.h 在您的TabMenu.h中

+ (id)tabMenu;

In your TabMenu.m add this function 在您的TabMenu.m中添加此功能

+ (id)tabMenu {
    TabMenu *customView = [[[NSBundle mainBundle] loadNibNamed:@“TabMenu” owner:nil options:nil] lastObject];
    // make sure customView is not nil or the wrong class!
    if ([customView isKindOfClass:[TabMenu class]])
        return customView;
    else
        return nil;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM