我尝试在 UIViewcontroller 中创建 UItabbarcontroller。但是当我点击标签栏项目(firstview)时,它会在根视图控制器的顶部显示导航栏。我设置了标题,但没有显示。
代码创建UITabBarcontroller:
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];
和 Firstviewcontroller 中的代码:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
userLogin1 =[[NSUserDefaults standardUserDefaults]valueForKey :@"textfieldtext"];
NSLog(@"User login: %@",userLogin1);
self.navigationItem.title = [NSString stringWithFormat: @"Hello, %@",userLogin1]; // it not works
}
请看这张图片: 它只显示按钮返回,它不显示标题。我不知道为什么。