2012-03-22 85 views
0

我想添加一些按钮到我的导航控制器的工具栏:我看到工具栏,但没有按钮。这是我的代码,我设置工具栏部分...导航控制器工具栏按钮问题 - Xcode

(这是我的AppDelegate)

// Create a table view controller 
    RootViewController *rootViewController = [[RootViewController alloc] 
               initWithStyle:UITableViewStyleGrouped]; 

    rootViewController.managedObjectContext = context; 
    rootViewController.entityName = @"County"; 

    //Navigation Controller 
    UINavigationController *aNavigationController = [[UINavigationController alloc] 
                initWithRootViewController:rootViewController]; 

    self.navigationController = aNavigationController; 


    //Barbuttons 
    UIBarButtonItem *homeButton; 
    homeButton = [[[UIBarButtonItem alloc] initWithTitle:@"   Inizio   " style:UIBarButtonItemStyleBordered target:self action:@selector(home)] autorelease]; 

    UIBarButtonItem *barButton; 
    barButton = [[[UIBarButtonItem alloc] initWithTitle:@" Funzioni online " style:UIBarButtonItemStyleBordered target:self action:@selector(caricamappa)] autorelease]; 

    UIBarButtonItem *creditsButton; 
    creditsButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"credits2.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(credits)] autorelease];  

    NSArray *baritems = [NSArray arrayWithObjects: homeButton, barButton, creditsButton, nil]; 

    [window addSubview:[navigationController view]]; 
    [self.navigationController.toolbar setItems:baritems]; 
    [self.navigationController setToolbarHidden:NO]; 


    [window makeKeyAndVisible]; 

    [rootViewController release]; 
    [aNavigationController release]; 

关于我的错误任何想法?

回答

0

退房the documentation,特别是这部分:

的这个工具栏的内容管理是通过自定义视图与此导航控制器相关 控制器来完成。对于导航堆栈中的每个视图 控制器,可以使用setToolbarItems:animated: UIViewController的方法分配一组自定义的 工具栏项目。

1

您应该将按钮添加到您的rootViewController的navigationItem属性,而不是导航控制器的工具栏。 类似于:

rootViewController.navigationItem.rightBarButtonItems = barItems;