限制NSArrayController中的对象数 [英] Limiting the number of objects in NSArrayController

查看:153
本文介绍了限制NSArrayController中的对象数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程式中建立某种「前25名」名单。我使用NSPredicate过滤数组控制器的内容,但我想限制结果的数量只有25个对象。

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?

推荐答案

另一种策略是子类化NSArrayController并覆盖arrangeObjects,返回类似 [[super arrangedObjects] subarrayWithRange:NSMakeRange(0,25)]; (你可能想先检查数组的长度)。当然,这个数组控制器只适用于前25个,而在你的应用程序中其他地方。

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.

这篇关于限制NSArrayController中的对象数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆