2012-09-06 80 views
0

可能重複:
adding more than two button on the navigationbar添加兩個或多個按鈕上的導航欄

如何在navaigationbar添加兩個按鈕?。我的代碼是follow.if我使用rightBarButtonItem方法沒有問題的項目。

UIBarButtonItem *barPrint = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"tool_print.png"] 
                    style:UIBarButtonItemStylePlain 
                    target:self 
                    action:@selector(printAttach:)]; 
     UISwitch *OnOff = [[UISwitch alloc] init]; 
     UIBarButtonItem *barOnOff = [[UIBarButtonItem alloc] initWithCustomView:OnOff]; 

     //[onoff1 addTarget: self action: @selector(flip:) forControlEvents:UIControlEventValueChanged]; 
     self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:barOnOff, barPrint, nil]; 
     [OnOff release]; 
+0

嘗試'self.navigationController.navigationBar.items = [NSArray的arrayWithObjects:...]' – 2012-09-06 14:50:09

+0

代碼是好的,但問題是不明確......你得到在酒吧2項? – vishy

+0

錯誤是在運行時間..如果我只顯示一個項目,那麼它是好的,有沒有我的代碼有問題?..我對我的barPrint按鈕有疑問。 – Sabareesh

回答

0
UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,32,32)]; 
[iv setBackgroundColor:[UIColor whiteColor]]; 
    self.navigationItem.titleView = iv;