【问题标题】:NSToolbar insertItemWithItemIdentifier:atIndex: call results in "Unable to simultaneously satisfy constraints" exceptionNSToolbar insertItemWithItemIdentifier:atIndex:调用导致“无法同时满足约束”异常
【发布时间】:2014-04-25 15:39:01
【问题描述】:

在使用自动布局的窗口中,以下代码会导致自动布局“无法同时满足约束”异常:

  [self.toolbar insertItemWithItemIdentifier:@"MyID" atIndex:2];

异常详情如下:

2014-04-25 17:31:41.354 AppName[5100:303] Unable to simultaneously satisfy constraints:
(
    "<NSAutoresizingMaskLayoutConstraint:0x108adef10 h=--& v=--& V:[NSToolbarItemViewer:0x101d3ef80(5)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x108ade420 h=--& v=-&- V:|-(10)-[_NSToolbarSpace:0x101d37ae0]   (Names: '|':NSToolbarItemViewer:0x101d3ef80 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x108ade3c0 h=--& v=-&- V:[_NSToolbarSpace:0x101d37ae0]-(11)-|   (Names: '|':NSToolbarItemViewer:0x101d3ef80 )>"
)

Will attempt to recover by breaking constraint 
<NSAutoresizingMaskLayoutConstraint:0x108ade420 h=--& v=-&- V:|-(10)-[_NSToolbarSpace:0x101d37ae0]   (Names: '|':NSToolbarItemViewer:0x101d3ef80 )>

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.  And/or, break on objc_exception_throw to catch this in the debugger.

工具栏项插入到灵活空间项的后面。部分工具栏在 IB 中配置,但我需要动态填充一些按钮。

由于在 IB 工具栏中的任何地方都没有手动指定的约束,我有点不知道从这里去哪里..

只要将工具栏项插入工具栏中,一切最终都会正常工作。

【问题讨论】:

    标签: cocoa autolayout nstoolbar nstoolbaritem


    【解决方案1】:

    FWIW - 在删除(预配置的)工具栏中的最后一个项目后异常消失了,该项目恰好是一个灵活空间项目

    现在我只需要想办法让所有工具栏项居中..

    (这是低于 10.8/10.9)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 2014-06-19
      相关资源
      最近更新 更多