我有一个基于选项卡的应用程序,当单击一个按钮将加载新的Uiview时,我试图更改UINavigationBar的标题,但未显示任何内容!

我创建这样的栏:

navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 60)];
navBar.barTintColor = [UIColor colorWithRed:0.082 green:0.118 blue:0.141 alpha:1.0];
navBar.tintColor = [UIColor whiteColor];
navBar.translucent = NO;
[self.view addSubview:navBar];


然后在方法中,我尝试更改:

UIView *sendASongView = [[UIView alloc] init];
[sendASongView setFrame: CGRectMake(0, 60, screenWidth, screenHeight-110)];
[sendASongView setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:sendASongView];
navBar.topItem.title = @"Send";

最佳答案

您可以创建一个UINavigationController并将其用作viewController的容器。

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {

    self.statusLabel.text = @"You're logged in as";

    HomeNavViewController *profileviewController = [[HomeNavViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: profileviewController] ;


    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [self.view.window.layer addAnimation:transition forKey:nil];
    [self presentModalViewController:nav animated:NO];

}


覆盖viewWillAppear中的方法YourViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated] ;
    self.title = @"Sender" ;
}

10-08 19:29