NSView上的自动布局约束只有在命中边缘后才会出现

时间:2014-09-21 00:19:39

标签: objective-c macos autolayout nstableview nsview

Shown on 10.10, but reproduced on 10.7 and above

(显示于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]];
}
}

}

enter image description here

1 个答案:

答案 0 :(得分:1)

[tableColumn setWidth:self.view.superview.frame.size.width]

- (NSView *)tableView:(NSTableView *)tableView
   viewForTableColumn:(NSTableColumn *)tableColumn
                  row:(NSInteger)row