无法向标签栏控制器视图添加第二个标签栏

时间:2013-12-05 04:34:16

标签: ios iphone tabs uitabbarcontroller

我正在尝试在标签栏控制器的第一个视图的顶部添加第二个标签栏,但出于某种原因,它控制了底部的标签栏并将所有内容添加到第一个标签按钮。我看不出我做错了什么,任何帮助都会受到赞赏。

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...";

enter image description here

1 个答案:

答案 0 :(得分:1)

成功创建标签栏后,请在窗口中将根视图设置为标签栏。像

一样
    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;

因此,请确保创建标签栏并将其添加到正确的位置。