ios MagicalRecord 排序.需要部分标题列表 [英] ios MagicalRecord sorting. Need a list of section headers

查看:20
本文介绍了ios MagicalRecord 排序.需要部分标题列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 MagicalRecord 访问的核心数据模型.我使用此代码来获取按类别排序和分组的 tableview:

I have a Core Data model accessed using MagicalRecord. I use this code to get a tableview sorted and grouped by categories:

frc = [ListActivity MR_fetchAllSortedBy:@"activityCategory,activityName"
                                  ascending:YES withPredicate:nil
                                    groupBy:@"activityCategory"
                                   delegate:nil];

生成的 tableview 如下所示:

The resulting tableview looks like this:

在另一个视图中,我使用相同的数据,但这次只需要一个由属性activityCategory"表示的节标题列表.我以为这是一件简单的事情,但事实并非如此.这段代码,例如:

In another view, I use the same data, but this time want only a list of the section headers, represented by the attribute "activityCategory". I expected it to be a simple matter, but not so. This code, for example:

frc = [ListActivity MR_fetchAllSortedBy:@"activityCategory"
                              ascending:YES withPredicate:nil
                                groupBy:nil
                               delegate:nil];

产生这个:

相反,我想要的只是一个类别列表(单独),在第一个示例中提供部分标题的属性.我尝试了其他几种配置,但意识到我只是将东西扔到墙上看它是否会粘住.MagicalRecord 的文档与框架一样出色,但可悲的是缺乏.

Instead, what I want is just a list of the categories (singularly), the attributes that provide the section headers in the first example. I tried a couple of other configurations, but realized I was just throwing stuff against the wall to see if it would stick. The documentation for MagicalRecord, as excellent as the framework is, is lamentably scant.

有人可以给我指出解决方案吗?

Can someone please point me at the solution?

谢谢!

推荐答案

您可能需要考虑拥有一个 ListActivityCategory 实体以及将类别存储为 ListActivity 上的字符串>

You might want to consider having a ListActivityCategory entity as well as storing the category as a String on ListActivity

这样你就可以在所有返回的 ListActivity 对象中获取那些而不是唯一"的对象

That way you could fetch those instead of haven to 'unique' across all the returned ListActivity objects

这篇关于ios MagicalRecord 排序.需要部分标题列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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