簡體   English   中英

iOS創建沒有情節提要的TabController

[英]iOS Create TabController without storyboard

也許是愚蠢的,但我感到困惑,找不到沒有情節提要創建UITabBarController的任何示例。

我只有單視圖應用程序。 然后我按下按鈕,我想要presentITController是UITabBarController

我的xib UITabBarController看起來像 在此處輸入圖片說明

如你所見,我有兩個TabBarItems,但是隨后我在模擬器上運行了這張照片

在此處輸入圖片說明

我的標簽欄控制器的此處界面

@interface TabsViewController : UITabBarController

我展示它

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

我也不想通過代碼創建它,我想使用xib。

在.h ViewController文件中,導入選項卡菜單:

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

在您的.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];
}

在您的TabMenu.h中

+ (id)tabMenu;

在您的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