1

In a window that uses auto layout the following code results in an auto layout "Unable to simultaneously satisfy constraints" exception:

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

Exception details is as follows:

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.

The toolbar item is inserted just behind a flexible space item. Parts of the toolbar are configured in IB but I need to populate a number of buttons dynamically.

As there are no manually specified constraints anywhere in the toolbar in IB I'm kind of clueless where to go from here..

Everything eventually works fine as far as the toolbar item is inserted into the toolbar.

4

1 回答 1

4

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

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

(这是低于 10.8/10.9)

于 2014-05-03T09:57:56.323 回答