Limiting the number of objects in NSArrayController

隐身守侯 提交于 2019-12-25 00:20:57

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/694493/limiting-the-number-of-objects-in-nsarraycontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!