在NSOutlineView源列表中取消选择行时,行文本向上移动

时间:2013-06-29 18:06:56

标签: macos cocoa nsoutlineview

在我的应用程序中,我设置了一个NSOutlineView,它只显示类别作为一种菜单。 这很好用,但是当我取消选择一个项目时会出现问题,每行中的标题会向上移动,如下图所示:

NSOutlineView deselection problem

她是我正在使用的代码:

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {

    return [sectionsArray  count];
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {

    return NO;
}

-(BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item {

    return NO;
}

- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {

    NSTableCellView *cellView = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
    cellView.imageView.image = [NSImage imageNamed:@"Point.png"];
    cellView.textField.stringValue = item;

    SectionCellCountField *number = [[SectionCellCountField alloc] initWithFrame:NSMakeRect(cellView.frame.size.width-50, 4, 35, 16)];
    [cellView addSubview:number];

    int rows = 0;

    for (int i = 0; i < [dataArray count]; i++) {

        if ([item isEqualToString:[[dataArray objectAtIndex:i]valueForKey:@"Cathegory"]]) {

            rows = rows +1;
        }

    }

    number.stringValue = [NSString stringWithFormat:@"%i", rows];

    return cellView;
}

- (id)outlineView:(NSOutlineView *)outlineView
        child:(NSInteger)index
       ofItem:(id)item {

    return [sectionsArray objectAtIndex:index];

}

任何人都知道为什么会出现这种情况? 非常感谢!

1 个答案:

答案 0 :(得分:2)

您使用的是autolayout吗?当我忘记限制至少两个表格单元视图子视图的顶部,底部或高度时,我已经看到了这种情况。关于表格和大纲视图的某些内容往往会使模糊布局起作用。