NavigationBar没有出现在我的ViewController上

时间:2010-07-18 06:00:52

标签: iphone objective-c cocoa-touch uiview uiviewcontroller

我有一个以模态方式呈现的UIViewController。 UIViewController位于UINavigationController内。

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" 
                                                  style:UIBarButtonItemStyleBordered 
                                                  target:self 
                                                  action:@selector(saveButtonClicked:)]; 


    self.navigationItem.rightBarButtonItem = saveButton;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1];
    self.title = @"Login";
    //toolbar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1];
}

为什么我的导航栏不显示文本登录和右侧的保存按钮?

2 个答案:

答案 0 :(得分:3)

听起来您可能正在呈现视图控制器而不是导航控制器。用于呈现您所描述的视图控制器的代码应如下所示:

MyViewController *viewController = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self presentModalViewController:navController animated:YES];
[viewController release];
[navController release];

答案 1 :(得分:0)

在加载nib之后设置属性,但是在推送它之后你可能需要这样做。