【发布时间】: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