我實現NSOutlineView,並具有實現以下方法父/子元素,NSOutlineView問題與
-(void) initOutlineView{
pMyOutlineView = [[[MyUICustomOutlineView alloc] initWithFrame:clipViewBounds]
autorelease];
NSTableColumn* firstColumn = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
[firstColumn setWidth:25];
[pMyOutlineView addTableColumn:firstColumn];
NSTableColumn* secondColumn = [[[NSTableColumn alloc] initWithIdentifier:@"secondColumn"] autorelease];
NSTextFieldCell *pCell = [[NSTextFieldCell alloc]init];
[secondColumn setDataCell:pCell];
[secondColumn setWidth:180];
[pMyOutlineView addTableColumn:secondColumn];
[pMyOutlineView setRowHeight:30];
pNodeArray = [[NSMutableArray alloc]initWithCapacity:10];
PointerNode *pNode = pointerList.getHead();
int idx =0;
void *ptr = nil;
while (contact) {
[pNodeArray insertObject:[NSValue valueWithPointer:(void *)pNode]
atIndex:idx];
pNode = pNode->getNext();
idx++;
}
[pMyOutlineView setDataSource:self];
// this is to tell myCustomOutlineView to delegate Menu and Mouse event to
// this interface
[pMyOutlineView setDataDelegate:self];
[scrollView setDocumentView:pMyOutlineView];
[pMyOutlineView setDelegate:self];
}
並實施以下的委託方法
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
// Here it will come for the top level element
if(item==nil)
return pointerList.size();
/*
If its not NULL then it must be some child element
*/
if([item isKindOfClass:[NSValue class]])
{
// yes it may have children
PointerNode *pNode = (PointerNode *)[item pointerValue];
if(pNode->hasChildren()){
return pNode->getNoOfChild();
}
}
return 0; // means this element not going to have any children
}
其他一些方法
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
和獲取數據
我正在關注一些博客,教程, 我面臨的問題是作爲參數文檔,它應該在numberOfChildrenOfItem中爲我們需要計算的每個元素髮送併發送該項目的子項號爲 ,但問題是什麼它正在面對,它的上述功能只有一次,對於這個項目是零,即它不來其他元素, 我是否缺少任何方法,需要委託
我重寫的其他方法如下,
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)aTableColumn byItem:(id)item
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
請告訴我,我缺少哪種方法
你好,非常感謝,我錯過了一種方法來實現 - (void)isGroupItem,所以它沒有設置爲一個組項目 – Amitg2k12 2011-01-30 11:18:42