在我的应用程序中,我设置了一个 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];
}
有人知道为什么会发生这种行为吗?非常感谢!