当行扩展/折叠时,我试图修改在NSOutlineView中使用的自定义NSTableRowView的外观。我的NSOutlineViewDelegate包括:
- (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item
{
...
return rowView;
}
- (void)itemDidExpand:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
id item = [userInfo objectForKey:@"NSObject"];
NSOutlineView *outlineView = [notification object];
[outlineView reloadItem:item];
}
不幸的是,这不会重新加载自定义行视图。
重新加载整个NSOutlineView的数据:
- (void)itemDidExpand:(NSNotification *)notification
{
[outlineView reloadData];
}
但是,如果有大量数据,这可能很耗时,并且经常导致旋转的沙滩球。
是否可以仅针对单个顶级项目重新加载自定义行视图?
请尝试以下方法:
-(void)outlineView:(NSOutlineView *)outlineView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
aColor = [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0];
[view setBackgroundColor:aColor];
}
您可以进一步前进以获取行对象,然后确定特定行要使用的颜色。
-编辑-
如果要更改父单元格视图以显示其已扩展,则对NSOutlineview实施了错误的方法。实现如下所示的方法:
-(void)outlineViewItemWillExpand:(NSNotification *)notification {
id theObject = [[notification userInfo] objectForKey:@"NSObject"];
NSInteger row = [theOutlineView rowForItem:theObject];
NSTableRowView *theRowView = [theOutlineView rowViewAtRow:row makeIfNecessary:NO];
int r = 110;
int g = 110;
int b = 110;
NSColor *aColor = [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0];
[theRowView setBackgroundColor:aColor];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句