2012-03-22 83 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;