我的大纲视图,我正在添加自定义单元格,绘制自定义单元格,我指的是示例代码,存在于
Cocoa文档中
http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/
我想用我的自定义图像更改单元格的显示图像,我尝试过以下操作
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item { if([item isKindOfClass:[NSValue class]]) { MyData *pDt = (MyData *)[item pointerValue]; if(pDt->isGroupElement()) { [cell setImage:pGroupImage]; } } }
但那也没有用,有没有其他方法来改变披露形象,
另外我怎么能在willDisplayCell中找到Item是展开还是折叠,所以我可以相应地设置图像,这只是改变披露形象的地方吗?
你有基本的想法,但你需要做的是自己绘制图像.这是我使用的代码:- (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSString *theImageName; NSInteger theCellValue = [cell integerValue]; if (theCellValue==1) { theImageName = @"PMOutlineCellOn"; } else if (theCellValue==0) { theImageName = @"PMOutlineCellOff"; } else { theImageName = @"PMOutlineCellMixed"; } NSImage *theImage = [NSImage imageNamed: theImageName]; NSRect theFrame = [outlineView frameOfOutlineCellAtRow:[outlineView rowForItem: item]]; theFrame.origin.y = theFrame.origin.y +17; // adjust theFrame here to position your image [theImage compositeToPoint: theFrame.origin operation:NSCompositeSourceOver]; [cell setImagePosition: NSNoImage]; }
您将需要3个不同的图像,一个用于ON状态,一个用于OFF状态,另一个用于MIXED状态,应该在两者之间.混合状态确保您仍然可以获得开始和结束动画.
精彩评论