How to add UITabBarController programmatically (no xib file or storyboard)

后端 未结 3 1263
感情败类
感情败类 2020-12-28 20:52

I want to add a UITabBarController to my application. But I have to do it with code only. No xib files or storyboards. How to do this entirely through code?

3条回答
  •  感动是毒
    2020-12-28 21:42

    Add this code in your AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
       FirstViewController * fvc=[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
    
       SecondViewController * svc=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    
    
       ThirdViewController * tvc=[[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
    
       FourthViewController * fvc2=[[FourthViewController alloc]initWithNibName:@"FourthViewController" bundle:nil];
    
    
       tabbar=[[UITabBarController alloc]init];
    
       tabbar.viewControllers=[NSArray arrayWithObjects:fvc,svc,tvc,fvc2,nil];
    
       [self.window addSubview:tabbar.view];
    }
    

提交回复
热议问题