views:

210

answers:

2

I'm trying to create some kind of "Top 25" list in my app. I've used NSPredicate to filter the contents of the array controller but I want to limit the number of the results to just 25 objects. How could I do that?

+3  A: 

Add sort descriptors to the same array controller, set its selection indexes to the range { 0, 25 }, then bind to (or directly access) either its selection or its selectedObjects.

Peter Hosey
+2  A: 

Another strategy would be to subclass NSArrayController and override arrangedObjects to return something like [[super arrangedObjects] subarrayWithRange:NSMakeRange( 0, 25 )]; (you would probably want to check the length of the array first). Of course this array controller would only be good for the top 25, and nowhere else in your application.

Marc Charbonneau