多个UIBarButton项目

时间:2012-11-13 07:06:38

标签: objective-c ios xcode

我无法使用“界面”构建器设置几个UIBarButton项目。

以下是我的界面构建器中的层次结构:

View controller:
    View:
         TableView
    Navigation Item:
         BarButtonItem:
              Button on left
         BarButtonItem:
              Button on right

问题是我无法在BarButtonItem上添加多个按钮,尝试只拖动另一个按钮会让第一个按钮覆盖..

为了获得更清晰的视野,我现在有两个按钮,左边是右边一个。他们俩工作得很好。问题是要像右侧的另一个按钮一样。

我希望这个问题很清楚,如果您有任何疑问请咨询。

2 个答案:

答案 0 :(得分:0)

不确定您是否可以在Interface Builder中执行此操作,但您绝对可以以编程方式执行此操作。

对于iOS 5.0及更高版本,您可以将UIBarButtonItems添加到 rightBarButtonItems (Interface Builder不会公开)。

- (void)viewDidLoad 
{
    [super viewDidLoad];

    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
    UIBarButtonItem *barButtonItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];

    self.navigationItem.rightBarButtonItems = @[barButtonItem, barButtonItem2];
}

对于iOS 5之前的版本,它有点困难。您首先必须将barButtonItems添加到UIToolbar,然后将rightBarButtonItem设置为barButtonItem,并将该UIToolbar作为其自定义视图。

答案 1 :(得分:0)

而不是将Button放在BarButton中。试试这样。

Navigation Item:
     BarButtonItem:
          Button on left
     BarButtonItem:
          View: // Stuff on right
               Button one
               Button two

这应该有用。