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

前端 未结 10 1388
猫巷女王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

    [view2Controller setTitle:@"ImATitle"];
    

    might be what your after

    edit: ok i just tested this and it def works for me so give it a go

    UINavigationController *nav1 = [[UINavigationController alloc] init]; 
    myViewController *myView = [[myViewController alloc] init];
    //myView.title = @"Title"; //prob not needed
    [nav1 pushViewController: myView  animated:NO];
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Title" image:[UIImage      imageNamed:@"title.png"] tag:0];
    nav1.tabBarItem = item;
    UITabBarController *tbc = [[UITabBarController alloc] init];
    tbc.viewControllers = [NSArray arrayWithObjects:nav1, nil];
    

提交回复
热议问题