NOrder
NOrder

Reputation: 2493

why objectValueForTableColumn is called so many times for outlineView?

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

Answers (1)

Milliways
Milliways

Reputation: 1275

  1. if there are 32 files under the "/", the method

    • (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item

will be called for each row and column as it is displayed. I assume you have 2 columns and 31 rows are actually shown.

  1. the method doesn't have a parameter about the row, then how the cocoa to determine which row the item should be displayed?

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

Related Questions