How to set tab bar item title programmatically in objective c?

前端 未结 10 1372
猫巷女王i
猫巷女王i 2021-01-31 15:46

I want to set title to tab item programatically, but it not works. My code is below:

- (IBAction)tab1Click:(id)sender {
    myTabBarController = [[UITabBarContro         


        
10条回答
  •  日久生厌
    2021-01-31 16:25

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
        UITabBarController *tb=[[UITabBarController alloc]init];
        UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main"   bundle:nil];
        UIViewController *vc1=[sb   instantiateViewControllerWithIdentifier:@"View1"];
        UIViewController *vc2=[sb   instantiateViewControllerWithIdentifier:@"View2"];
    
          //To Set Title for UIViewController
    
          [vc1 setTitle:@"View1"];
          [vc2 setTitle:@"View2"];
    
    
        NSArray *vController=[[NSArray alloc]initWithObjects:vc1,vc2,nil];
        tb.viewControllers=vController;
        self.window.rootViewController=tb;
        [self.window makeKeyAndVisible];
    
    
      return YES;
    }
    

提交回复
热议问题