the*_*end 4 cocoa nstableview nsscrollview nslayoutconstraint
我正在以编程方式在NSScrollView中创建NSTableView,但是当我尝试将框架设置为滚动视图时,我遇到了约束错误.
Unable to simultaneously satisfy constraints:
(
"<NSAutoresizingMaskLayoutConstraint:0x107d4ec50 h=--& v=--& V:[NSScrollView:0x10068c570(372.5)]>",
"<NSAutoresizingMaskLayoutConstraint:0x107d4d020 h=-&- v=-&- V:[NSClipView:0x10068d7f0]-(673)-| (Names: '|':NSScrollView:0x10068c570 )>",
"<NSAutoresizingMaskLayoutConstraint:0x107d4cfc0 h=-&- v=-&- V:|-(2)-[NSClipView:0x10068d7f0] (Names: '|':NSScrollView:0x10068c570 )>"
)
Will attempt to recover by breaking constraint
<NSAutoresizingMaskLayoutConstraint:0x107d4d020 h=-&- v=-&- V:[NSClipView:0x10068d7f0]-(673)-| (Names: '|':NSScrollView:0x10068c570 )>
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.
Run Code Online (Sandbox Code Playgroud)
看起来它们是自动创建的.
这是我的创建代码(使用arc)我是NSView的子类
-(void)addColumnsToTable{
NSTableColumn *col = [[NSTableColumn alloc]initWithIdentifier:@"priority"];
[col.headerCell setStringValue:@"priority"];
[col setWidth:10];
[col setMinWidth:1];
[col setMaxWidth:10];
[self.tableView addTableColumn:col];
// col = [[NSTableColumn alloc]initWithIdentifier:@"name"];
// [self.tableView addTableColumn:col];
}
-(void)createTable{
NSTableView *tableView = [[NSTableView alloc]initWithFrame:NSZeroRect];
[tableView setDelegate:self];
[tableView setDataSource:self];
NSScrollView *scrollView = [[NSScrollView alloc]initWithFrame:self.bounds];
[scrollView setBorderType:NSGrooveBorder];
[self addSubview:scrollView];
[scrollView setDocumentView:tableView];
[scrollView setHasVerticalScroller:YES];
[scrollView setAutohidesScrollers:YES];
self.tableView = tableView;
self.scrollView = scrollView;
[self addColumnsToTable];
}
Run Code Online (Sandbox Code Playgroud)
这是它破碎的地方:
-(void)setFrame:(NSRect)frameRect{
[super setFrame:frameRect];
[self.scrollView setFrame:self.bounds];
}
Run Code Online (Sandbox Code Playgroud)
有没有办法关闭这些自动约束?
知道了,问题是基于视图的自动调整大小掩码创建了自动约束.要停用此行为:
[scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
Run Code Online (Sandbox Code Playgroud)
其中scrollView是NSView的子视图
| 归档时间: |
|
| 查看次数: |
3814 次 |
| 最近记录: |