在导航栏上添加两个或更多按钮

时间:2012-09-06 14:41:34

标签: iphone ipad uinavigationbar

  

可能重复:
  adding more than two button on the navigationbar

如何在navaigationbar上再添加两个按钮?。我的代码如下。如果我使用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];

1 个答案:

答案 0 :(得分:0)

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