Re: NSTableView questions...
Re: NSTableView questions...
- Subject: Re: NSTableView questions...
- From: Scott Anguish <email@hidden>
- Date: Sun, 7 Sep 2003 00:33:50 -0400
On Sep 6, 2003, at 11:26 PM, Thomas McQuitty wrote:
I run through and get a list of data...
The user will select one or more items from the NSTableView.
I go to process this data when they select a button...
Now, I need to get a list of the items selected (like NSTableView
-isRowSelected:) but I cannot see an easy way to translate this back
to the text...
My questions are:
Am I approaching this the right way? Would scanning for the
correlated data in the datasource object be the right way to go? Are
these kept correlated? (I assume not).
They data is displayed in the same order that it is stored in the
datasource, so, yes.
What would the proper approach be, from a cocoa perspective...
Basically, what you do is get an enumerator on the selected rows in
the tableview (-selectedRowEnumerator) and then iterate over that. It
will return an NSNumber indicating the index of the object in the
datasource for each selectedRow in the tableview.
this method will return an array containing the objects.
You could generalize this more, and add it into a category on
NSTableView. You'd need to be able to get the raw object for the
datasource, perhaps by extending the NSTableDataSource protocol
informally, adding a
tableView:objectValueForTableRow: method to your datasource objects,
and then have the datasource return the raw row object in response to
receiving that message.
- (NSArray *)objectsInSelectedRows
{
NSMutableArray *tempArray=[[NSMutableArray alloc]
initWithCapacity:[theTableView numberOfSelectedRows]];
NSArray *returnResult;
NSEnumerator *indiceEnumerator;
NSNumber *eachRow;
indiceEnumerator=[theTableView selectedRowEnumerator];
while ((eachRow = [indiceEnumerator nextObject]))
{
[tempArray addObject:[WHATEVERYOURDATASOURCEIS
objectAtIndex:[eachRow intValue]];
}
returnResult=[NSArray arrayWithArray:tempArray];
[tempArray release];
return returnResult;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.