(显示于10.10,但转载于10.7及以上)
我有一个Mac菜单栏应用程序,首先加载NSOutlineView并填充一些基于视图的单元格。选择单元格后,隐藏NSOutlineView,并显示新的NSTableView(TicketViewController)。自定义NSTableViewCell(CommentComposeCellView)包含NSTextView和包含NSImageView和NSButton的自定义NSView(CommentComposeFooterView)。 NSTableViewCell和自定义NSView都具有Autolayout约束,因此它们应该与它们所包含的窗口大小相匹配。但是,在调整窗口大小时,自定义NSView不会调整大小,直到窗口的边缘接触到自定义NSView。
-(void)outlineViewSelectionDidChange:(NSNotification *)notification{
if ([self.outlineView selectedRow] != -1) {
id clickedItem = [self.outlineView itemAtRow:[self.outlineView selectedRow]];
if ([clickedItem isKindOfClass:[Request class]]){
[self.ticketViewController displayRequest:clickedItem];
[self.scrollView setHidden:YES];
NSView *contentView = [self.window contentView];
[[self.ticketViewController view] setFrame:[contentView bounds]];
[[self.ticketViewController view] setTranslatesAutoresizingMaskIntoConstraints:NO];
[contentView addSubview:[self.ticketViewController view]];
NSView *ticketView = [self.ticketViewController view];
NSDictionary *views = NSDictionaryOfVariableBindings(ticketView);
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[ticketView]|"
options:0
metrics:nil
views:views]];
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[ticketView]|"
options:0
metrics:nil
views:views]];
}
}
}
答案 0 :(得分:1)
加
[tableColumn setWidth:self.view.superview.frame.size.width]
到
- (NSView *)tableView:(NSTableView *)tableView
viewForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row