How to add UITabbarController to UIViewController in iOs

前端 未结 2 2016
遥遥无期
遥遥无期 2021-01-06 02:55

How to push Viewcontroller with TabbarController? In Viewcontroller\'XIB, i created UITabbarController. Then i push this ViewController, but it not appear UITabbarController

2条回答
  •  轮回少年
    2021-01-06 03:34

    If You want to use UITabBarController in your UIViewController class then use this below code...

    UIViewController .h Class -

        @property (nonatomic, retain) UITabBarController *tab;
    

    UIViewController .m Class -

    Add this in ViewDidLoad method...

        self.tab=[[UITabBarController alloc]init];
    
        // FirstViewController
        First *fvc=[[First alloc]initWithNibName:nil bundle:nil];
        fvc.title=@"First";
        fvc.tabBarItem.image=[UIImage imageNamed:@"i.png"];
    
        //SecondViewController
        Second *svc=[[Second alloc]initWithNibName:nil bundle:nil];
        svc.title=@"Second";
        svc.tabBarItem.image=[UIImage imageNamed:@"im.png"];
    
        //ThirdViewController
        Third *tvc=[[Third alloc]initWithNibName:nil bundle:nil];
        tvc.title=@"Third";
        tvc.tabBarItem.image=[UIImage imageNamed:@"img.png"];
    
        self.tab.viewControllers=[NSArray arrayWithObjects:fvc, svc, tvc, nil];
    
        [self.view addSubview:self.tab.view];
    

    here First, Second and Third are three different UIViewControllers. And you don't need to give the action on Tabs.

    It will work...

提交回复
热议问题