How to add UITabbarController to UIViewController in iOs

前端 未结 2 1996
遥遥无期
遥遥无期 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...

    0 讨论(0)
  • 2021-01-06 03:34

    If you're are starter,best practice is to search in google for the latest api samples,then understand the code and make your own world.

    1) You can find the related sample codes from apple here.

    2) TweetieBar --Here is the sample code with custom TabBarController(TweetieTabBar)

    0 讨论(0)
提交回复
热议问题