On 5 Nov 2008, at 4:21 pm, Steven Riggs wrote:

Thanks for the clarification Graham. It seems that retrieving data ordered (rows and columns) the same as the view is a common task. Apples solutions are pretty well thought out and encompassing so I was surprised there was not an easier way to get it.


I think it is pretty well thought out, once you accept the wisdom of sticking ruthlessly to MVC.

Typically a table's source data might be kept in a NSMutableArray held by your controller, which is directly sortable using the sort descriptors maintained by the table view. You can get the objects that are selected using a line of code like this:

NSArray* selectedObjects = [mySortedListOfAllObjects objectsAtIndexes: [myTableView selectedRowIndexes]];

I find it hard to imagine a much easier way to get it - the array and table view classes dovetail really quite nicely! (And don't violate MVC).


Using KVC in your datasource also dovetails very nicely, for example:

- (id) tableView:(NSTableView*) aTableView objectValueForTableColumn: (NSTableColumn*) aTableColumn row:(int) rowIndex
{
return [[mySortedListOfAllObjects objectAtIndex:rowIndex] valueForKey:[aTableColumn identifier]];
}

So straightforward, you'd almost think it was designed this way ;-)


cheers, Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to