2

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

NSOutlineView 取消选择问题

她是我正在使用的代码:

- (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];

}

有人知道为什么会发生这种行为吗?非常感谢!

4

1 回答 1

2

你在使用自动布局吗?当我忘记约束表格单元格视图子视图的顶部、底部或高度中的至少两个时,我已经看到这种事情发生了。关于表格和大纲视图的某些东西往往会使模棱两可的布局出现。

于 2013-12-16T01:40:23.180 回答