简体   繁体   中英

iOS Create TabController without storyboard

maybe stupid, but i'm in confuse, cant find any example creating UITabBarController without storyboard.

I have simply single view application. And then i press button i want presentViewController which is UITabBarController

My xib UITabBarController looks like 在此处输入图片说明

as u can see i have two TabBarItems, but then i run it's on simulator i got this picture

在此处输入图片说明

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.

In your .h ViewController file import the tab menu:

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

In your .m ViewController file:

- (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

+ (id)tabMenu;

In your TabMenu.m add this function

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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