如何修改此方法调用以便使用排序描述符进行排序?
我正在尝试对以下方法调用进行排序。我可以使用排序描述符吗?如果是这样我该怎么办?
NSArray *subcategoriesNames = [self.dataManager getSubcategoriesOfCategory:self.category];
for (SubcategoryEntity *subcategory in subcategoriesNames) {
NSLog(@"print all subcategories %@",subcategory.icon);
NSLog(@"print all subcategories %@",subcategory.title);
BaseTableItem *item = [[BaseTableItem alloc] initWithText:subcategory.title andIcon:subcategory.icon];
[self.tableItems addObject:item];
[item release];
我需要在循环中使用 subcategoriesNames 之前对其进行排序。
Datamanager
是一个Coredata
对象。它从数据库中检索一组行,每行都有一个标题和一个图标。我需要按标题进行排序。
I am trying to have the following method call, sorted. Can I use sortdescriptors? If so how should I do it?
NSArray *subcategoriesNames = [self.dataManager getSubcategoriesOfCategory:self.category];
for (SubcategoryEntity *subcategory in subcategoriesNames) {
NSLog(@"print all subcategories %@",subcategory.icon);
NSLog(@"print all subcategories %@",subcategory.title);
BaseTableItem *item = [[BaseTableItem alloc] initWithText:subcategory.title andIcon:subcategory.icon];
[self.tableItems addObject:item];
[item release];
I need that subcategoriesNames gets sorted before its used in the loop.
Datamanager
is a Coredata
object. Its retrieving a set of rows from a database, each row has a title and an icon. I need the sort to happen by title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能重复如何使用sortedArrayUsingDescriptors对NSMutableArray进行排序? ——那里的答案非常好。 – David Gelhar 4 月 18 日 2:41
possible duplicate of How to sort NSMutableArray using sortedArrayUsingDescriptors ? -- very good answers there. – David Gelhar Apr 18 at 2:41