【问题标题】:Multiple UIBarButton items多个 UIBarButton 项
【发布时间】:2012-11-13 15:53:15
【问题描述】:

我无法使用 Interface builder 设置几个 UIBarButton 项。

这是我在界面构建器中的层次结构:

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

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

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

我希望问题足够清楚,如果您有任何问题,请尽管提出。

【问题讨论】:

    标签: objective-c ios xcode


    【解决方案1】:

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

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

    这应该可行。

    【讨论】:

      【解决方案2】:

      不确定您是否可以在 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 作为其自定义视图。

      【讨论】:

      • 抱歉,我知道可以以编程方式完成,但希望通过界面生成器完成以节省一些时间。接受的答案是我的问题的正确解决方案,但感谢您抽出宝贵时间查看此问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 2014-04-25
      相关资源
      最近更新 更多