NSToolbar insertItemWithItemIdentifier:atIndex: call results in "Unable to simultaneously satisfy constraints" exception

StackOverflow https://stackoverflow.com/questions/23297446

Frage

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.

War es hilfreich?

Lösung

FWIW - the exception went away after removing the last item in the (preconfigured) toolbar which happened to be a Flexible Space item.

Now I just have to figure out a way to have all toolbar items centered..

(this is under 10.8/10.9)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top