我需要从NSTableView和NSOutlineView中删除未使用的单元格行。在UITableView中,我们有tablefooter的属性。有没有NSTableView的东西。
请检查代码及其相关说明。
dataArr是一个包含SearchItem类型对象的数组,它们只是数据的模态。 dataArr有4个对象意味着NSOutline视图中将出现总共4行。
((SearchItems *)item)。children是与单个SearchItems对应的OutlineView子项的数据数组。每行有2个孩子,所以当你展开行时,会有2个孩子出现。
//MARK: NSOutlineViewDataSource
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(nullable id)item
{
if (item != nil && [item isKindOfClass:[SearchItems class]])
{
return ((SearchItems *)item).children.count;
}
return dataArr.count;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(nullable id)item
{
if(item != nil && [item isKindOfClass:[SearchItems class]])
{
return ((SearchItems *)item).children[index];
}
return dataArr[index];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
if(item != nil && [item isKindOfClass:[SearchItems class]])
{
return ((SearchItems *)item).children.count > 0;
}
return false;
}
//MARK: NSOutlineViewDelegate
- (nullable NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(nullable NSTableColumn *)tableColumn item:(id)item
{
NSTableCellView *view;
if([item isKindOfClass:[SearchSubItems class]])
{
view = (NSTableCellView *)[outlineView makeViewWithIdentifier:@"SearchSubItem" owner:self];
view.textField.stringValue = ((SearchSubItems *)item).nameOfSubItem;
[view.textField sizeToFit];
}
else
{
view = (NSTableCellView *)[outlineView makeViewWithIdentifier:@"SearchItem" owner:self];
view.textField.stringValue = ((SearchItems *)item).nameStr;
[view.textField sizeToFit];
}
return view;
}