单击到Tabbaritem时选项卡向左移动(带有4个Tabbaritem)

时间:2018-08-16 20:26:54

标签: ios objective-c uitabbarcontroller uitabbar uitabbaritem

嗨,我在appDelegate中以编程方式创建的tabbarController setUp遇到了问题。我不知道问题出在哪里。

请帮助。

这是代码

AppDelegate.m

HomeTabBarViewController* homeVC = [[HomeTabBarViewController alloc] init];

    [self.window setRootViewController:homeVC];
    [self.window makeKeyAndVisible];

HomeTabBarViewController.h

-(void)setUpTabbarController{

    UIStoryboard * storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    HomeTabVC *view1 = (HomeTabVC*)[storyboard instantiateViewControllerWithIdentifier:@"HomeTabVC"];
    BookmarksViewController* view2=(BookmarksViewController*)[storyboard instantiateViewControllerWithIdentifier:@"BookmarksViewController"];
    UINavigationController * bookmarkNav=[[UINavigationController alloc]initWithRootViewController:view2];
    UINavigationController * nav1=[[UINavigationController alloc]initWithRootViewController:view1];

 LeftSideDrawer *view3 =(LeftSideDrawer*)[storyboard instantiateViewControllerWithIdentifier:@"LeftSideDrawer"];
    UINavigationController * nav3=[[UINavigationController alloc]initWithRootViewController:view3];

    LeftSideDrawer *view4 =(LeftSideDrawer*)[storyboard instantiateViewControllerWithIdentifier:@"LeftSideDrawer"];
    UINavigationController * nav4=[[UINavigationController alloc]initWithRootViewController:view4];
    view1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home"
                                                     image:[UIImage imageNamed:@"home_tab_item.png"] selectedImage:[UIImage imageNamed:@"home_tab_item_active.png"]] ;
    view2.tabBarItem =
    [[UITabBarItem alloc] initWithTitle:@"Your saves"
                                  image:[UIImage imageNamed:@"bookmark_tab_item.png"] selectedImage:[UIImage imageNamed:@"bookmark_tab_item_active.png"]];
    view3.tabBarItem =
    [[UITabBarItem alloc] initWithTitle:@"E-paper"
                                  image:[UIImage imageNamed:@"paper_tab_item.png"] selectedImage:[UIImage imageNamed:@"paper_tab_item_active.png"]];
    view4.tabBarItem =
    [[UITabBarItem alloc] initWithTitle:@"Categories"
                                  image:[UIImage imageNamed:@"menu_tab_item.png"] selectedImage:[UIImage imageNamed:@"menu_tab_item_active.png"]];
    NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
    [tabViewControllers addObject:nav1];
    [tabViewControllers addObject:bookmarkNav];
    [tabViewControllers addObject:nav3];
    [tabViewControllers addObject:nav4];
    [self setViewControllers:tabViewControllers];



}

0 个答案:

没有答案