-1

我尝试在 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

}

请看这张图片: 在此处输入图像描述 它只显示按钮返回,它不显示标题。我不知道为什么。

4

5 回答 5

3

像这样设置它:

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    userLogin1 =[[NSUserDefaults standardUserDefaults]valueForKey :@"textfieldtext"];
    NSLog(@"User login: %@",userLogin1);
//Here
    self.title = [NSString stringWithFormat: @"Hello, %@",userLogin1]; // it not works

}
于 2013-08-09T10:53:30.270 回答
2

看起来您正在添加UITabBarControllera UINavigationController,那么您需要执行以下操作:

self.parentViewController.navigationItem.title = [NSString stringWithFormat: @"Hello, %@",userLogin1];
于 2013-08-09T11:21:22.647 回答
0

You can set it like this

[self.tabBarController setTitle:@"Title"];
于 2013-11-17T10:33:58.463 回答
0

如果您想在导航栏中设置图像或颜色,请使用此代码..

     // For Background Image
     [[UINavigationBar appearance] setBackgroundImage:[UIImage 
     imageNamed:@"TitleImage.png"]] forBarMetrics:UIBarMetricsDefault];

     // For Background Color
     [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor 
     whiteColor]] forBarMetrics:UIBarMetricsDefault];

对于导航栏标题,请使用此代码...

     self.title = NSLocalizedString(@"FirstViewControllerTitle",nil);

                                     OR

     self.title = @"FirstViewControllerTitle";
于 2013-08-09T11:16:09.883 回答
0

UINavigationController为每个ViewControllerin设置UItabbarcontroller

UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:controller_1];

并为每个ViewController这样设置标题

self.title = @"yourTitle";
于 2013-08-09T11:16:52.853 回答