简体   繁体   中英

Can't add a second tab bar to tab bar controller view

I am trying to add a second tab bar at the top of the first view of a tab bar controller but for some reason it is taking control of the tab bar at the bottom and adding everything to the first tab button. I can't see what I am doing wrong, any help would be appreciated.

MainViewController *controller = self.storyboard.instantiateInitialViewController;

//************ Add Tab Bar ***********************************
self.tabsController = [[SGTabsViewController alloc] init];
self.tabsController.delegate = self;
self.window.rootViewController = self.tabsController;

[self.tabsController setToolbarHidden:NO animated:NO];

[self.tabsController addViewController:controller];

double delayInSeconds = 3.;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self.tabsController setToolbarHidden:NO animated:YES];
});

self.textTabField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 240.0, 30.0)];
self.textTabField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.textTabField.backgroundColor = [UIColor whiteColor];
self.textTabField.borderStyle = UITextBorderStyleRoundedRect;
self.textTabField.text = @"http://www.google.com";
self.textTabField.clearButtonMode = UITextFieldViewModeAlways;
self.textTabField.keyboardType = UIKeyboardTypeURL;
self.textTabField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textTabField.delegate = self;


UIBarButtonItem *urlBar = [[UIBarButtonItem alloc] initWithCustomView:self.textTabField];

UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                       target:nil action:nil];
UIBarButtonItem *reload = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                        target:self action:@selector(reload:)];
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                                     target:self
                                                                     action:@selector(add:)];


self.tabsController.toolbarItems = [NSArray arrayWithObjects:space,urlBar,space,reload,add,nil];
self.tabsController.title = @"Loading...";

在此处输入图片说明

Please set root view as tabbar in window after creating tab bar successfully. Like as

    ViewController1 checkinPage=[[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil];
    checkinPage.tabBarItem.title = @"Check In";
    checkinPage.tabBarItem.tag=1;
    checkinPage.tabBarItem.image = [UIImage imageNamed:@"tab_ic_CheckIn.png"];

    ViewController2 incentive=[[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
    incentive.tabBarItem.title=@"Incentives";
    incentive.tabBarItem.tag=2;
    incentive.tabBarItem.image=[UIImage imageNamed:@"tab_ic_Incentives.png"];
.tabBarItem.title = @"Check In";

   self.tabsController.viewControllers = [NSArray arrayWithObjects:checkinPage,incentive,nil];

   self.tabBar.selectedIndex=1;

   self.window.rootViewController = self.tabsController;

So please make sure about the tab bar creation and add them in right place.

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