2012-04-16 69 views
1

我正在使用XCode 4.3.1中的Master-Detail模板,並且想要訪問detailView控件上的工具欄。如何在iOS 5.1的uiSplitViewController中設置barButtonItems?

[自navigationItem]的setTitle:

設置了冠軍,但我無法弄清楚如何可以通過廈門國際銀行或編程方式添加barButtonItems。在過去,使用較早的SplitView模板(當主視圖稱爲根視圖時),我可以通過MainWindow.xib中的分割視圖控制器訪問rootView工具欄,並且我在detailView.xib文件中有detailView工具欄。

什麼是最好的方式來設置這些項目(我有4)在detailView工具欄上?

在此先感謝。

回答

0

所以我有一個答案 - 請讓我知道,如果你有一個更好的!

以我masterViewController的viewDidLoad方法我填充工具欄上的詳細視圖與

[_detailViewController.navigationItem setRightBarButtonItems:[NSArray的arrayWithObjects:_detailViewController.firstButton,_detailViewController.secondButton,_detailViewController.thirdButton,零] ]。

我創造了這些按鈕與

_detailViewController.firstButton = [[的UIBarButtonItem頁頭] initWithTitle:@ 「第一」 的風格:UIBarButtonItemStylePlain目標:自我行動:@選擇(firstButtonAction :)]。

我宣佈各自在detailViewController.h文件這些按鈕,這樣我可以在以後引用它們,但可能並不需要使用這些名字 - 它只是使代碼不在這裏了。我也有一個UIButton,我不能按鈕的數組中添加,所以我創建了一個按鈕,把它的一個視圖中,然後設置,作爲titleview的的導航項目:

_detailViewController.biggerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 230, 35)]; 
    [[_detailViewController biggerButton] addTarget:self action:@selector(biggerButtonTap:) forControlEvents:UIControlEventTouchUpInside]; 
UIView *biggerButtonView = [[UIView alloc] initWithFrame:CGRectMake(80, 3, 230, 35)]; 

    [biggerButtonView addSubview:_detailViewController.biggerButton]; 

    _detailViewController.navigationItem.titleView = biggerButtonView; 
相關問題