Reputation: 2493
I'm learning outline view of cocoa by Apple OS x developer library. The example source is like this:
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
return (item == nil) ? [FileSystemItem rootItem] : [(FileSystemItem *)item childAtIndex:index];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return (item == nil) ? YES : ([item numberOfChildren] != -1);
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
return (item == nil) ? 1 : [item numberOfChildren];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return (item == nil) ? @"/" : [item relativePath];
}
This will list all files in my system like a tree.
The question is:
1. if there are 32 files under the "/", the method
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
will be called 62 times, I don't know why?
2. the method
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
doesn't have a parameter about the row, then how the cocoa to determine which row the item should be displayed?
Upvotes: 0
Views: 517
Reputation: 1275
if there are 32 files under the "/", the method
will be called for each row and column as it is displayed. I assume you have 2 columns and 31 rows are actually shown.
The item
is a pointer to the object used to populate the table. This is all the NSOutlineViewDataSource Protocol
needs to know. Details of displayed rows in internal to the NSOutlineView
Upvotes: 1