Ios 实体和关系:如何配置我的tableview?

Ios 实体和关系:如何配置我的tableview?,ios,uitableview,core-data,nsfetchedresultscontroller,Ios,Uitableview,Core Data,Nsfetchedresultscontroller,我有两个实体,WMDGCategory和WMDGActivity。它们的关系配置如下: - (void)viewDidLoad { [super viewDidLoad]; catFRC = [WMDGCategory MR_fetchAllSortedBy:@"name" ascending:(YES) withPredicate:nil groupBy:@"name" delegate:nil]; actFRC = [WMDGActivity MR_fetchAllS

我有两个实体,
WMDGCategory
WMDGActivity
。它们的关系配置如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    catFRC = [WMDGCategory MR_fetchAllSortedBy:@"name" ascending:(YES) withPredicate:nil groupBy:@"name" delegate:nil];
    actFRC = [WMDGActivity MR_fetchAllSortedBy:@"name" ascending:YES withPredicate:nil groupBy:@"catFRC.activities" delegate:nil];

    [self.tableView reloadData];

}

我希望我的tableview显示根据相关的
WMDGCategory.name
在节标题下分组的
WMDGActivity
s

在用一个
NSFetchedResultsController
(尽管有些帖子声称可以做到这一点)惨败后,我决定尝试两个独立的FRC,
catFRC
actFRC
。目前声明如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    catFRC = [WMDGCategory MR_fetchAllSortedBy:@"name" ascending:(YES) withPredicate:nil groupBy:@"name" delegate:nil];
    actFRC = [WMDGActivity MR_fetchAllSortedBy:@"name" ascending:YES withPredicate:nil groupBy:@"catFRC.activities" delegate:nil];

    [self.tableView reloadData];

}
此时,我的tableviewDataSource方法如下所示。用此-->标记的伪代码显示了当前的混乱状态

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return [[catFRC sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.

    id<NSFetchedResultsSectionInfo> sectionInfo = [[catFRC sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    WMDGActivity *activityForCell = // ----> the activities pointed to by the "WMDGCategory" relationship "activities", sorted by "name"

    cell.textLabel.text = activityForCell.name;


    return cell;
}
回想起来,我在整个过程中遇到的问题源于我很难理解调用
WMDGActivity.category
是通过关系调用与
WMDGActivity
关联的
WMDGCategory
对象。我知道这听上去一定很愚蠢,但我很难理解这个概念


我欠你们和这里的其他人一份真正的感激之情。谢谢

由于每个活动都有一个对其所属类别的引用,因此您只需提出一个请求(针对活动),然后您就可以根据其各自的类别属性对其进行分组。

这种关系是相反的吗?如中所示,每个活动是否都有对其所属类别的引用?如果是这样的话,您只需要提出一个请求(针对活动),然后您就可以按照各自的类别属性对它们进行分组。是的,我应该提到这一点。我还应该提到,我正在使用MagicalRecord便利类来处理核心数据。然而,我试过使用一个FRC,我不知道如何配置它。为什么不询问使用1个FRC并描述您看到的问题?明白了!请参见上面的编辑。对于mMo,请点击这里的Upvote和绿色复选标记,@Wain,请在昨天的问题上查找您的答案。再次感谢@mMo——你能把你的建议变成一个答案吗?