Re: tableview multiple selected loop
Re: tableview multiple selected loop
- Subject: Re: tableview multiple selected loop
- From: Graham Cox <email@hidden>
- Date: Tue, 27 Jul 2010 23:05:20 +1000
On 27/07/2010, at 5:53 PM, Amy Gibbs wrote:
> If i've got multiple rows selected in a table view, and I want to do something with each of them, do I need some kind of loop in my code, or will cocoa automatically run the code for each selected row? I can't find any kind of while, foreach type of loop example anywhere?
The table's selection is expressed using an NSIndexSet object, retrieved using -selectedRowIndexes. You can use its methods such as -firstIndex, -nextIndexGreaterThan:, etc to iterate through the index values it contains, or use methods on other classes such as NSArray that take an NSIndexSet argument, like -objectsAtIndexes:
This latter is probably more common, since having got the subarray of objects of interest, you can enumerate those using NSEnumerator or fast enumeration, or just use the subarray as an argument elsewhere.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden