Reputation: 6122
Say I have a NSTableView (for example, a
) and a NSOutlineView (for example, b
).
In the datasource of a
I'm trying to get the parent item of all the selected items of b
. In the row no. rowIndex
of a
I would like to have the rowIndex
th selected item of b
and I would like to concatenate this string to the name of the parent of this item. For example, a
:
And b
:
This is - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
of a
.
NSUInteger index = [[outlineView selectedRowIndexes] firstIndex];
for (NSUInteger i = 0, target = rowIndex; i < target; i++)
index = [[outlineView selectedRowIndexes] indexGreaterThanIndex:index];
NSLog(@"%@", [outlineView [outlineView itemAtRow:index]]);
if([outlineView parentForItem:[outlineView itemAtRow:index]] != NULL) {
return [NSString stringWithFormat:@"%@ %@", [outlineView parentForItem:[outlineView itemAtRow:index]], [outlineView itemAtRow:index]];
} else {
return [outlineView itemAtRow:index];
}
return NULL;
The problem is that when I expand an item [outlineView parentForItem:[outlineView itemAtRow:index]]
returns always the last expanded item.
I am trying to have a list of selected items and their parents. When I expand an item, all items change their parent to last expanded item
.
Am I doing something wrong?
Thank you in advance.
Upvotes: 0
Views: 1521
Reputation: 4232
You can't use a simple integer to represent an index in a nested set of data, as you found out. Instead you need to use NSIndexPath. As the docs put it:
The NSIndexPath class represents the path to a specific node in a tree of nested array collections. This path is known as an index path.
Upvotes: 1