如何向UINavigationController添加按钮

时间:2010-05-20 16:08:33

标签: iphone objective-c

我有以下代码,将导航控制器添加到模态视图中。导航栏和视图都显示正常,但右键不显示。我做错了什么?

    UpgradesViewController* upgradesViewController = [[UpgradesViewController alloc] initWithNibName:@"UpgradesView" bundle:nil];
    upgradesViewController.title = @"Upgrades";

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:upgradesViewController];
    navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    navController.navigationBar.barStyle = UIBarStyleBlack;
    UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Show" style:UIBarButtonItemStylePlain target: self  action:nil];
    navController.navigationItem.rightBarButtonItem = doneButton;
    [self presentModalViewController:navController animated:YES];

    [navController release];
    [upgradesViewController release];

1 个答案:

答案 0 :(得分:10)

将doneButton添加到upgradesViewController的navigationItem,而不是navController。导航控制器显示顶部控制器的导航项,而不是其自身。