UITableView已按排序顺序剖切,剖切不正确

UITableView已按排序顺序剖切,剖切不正确,uitableview,core-data,nsfetchrequest,Uitableview,Core Data,Nsfetchrequest,因此,我试图获得一个UITableView,以按节(thing.title)显示对象列表,但按日期降序列出它们 该表被分为多个部分,这些部分正确地标记为(部分标题是不同的标题) 但每个部分中的对象只正确了一半。每个部分中的对象按降序列出,但某些部分包含应在其他部分中的数据 正在发生的事情的一个例子: <Header> Big Title Name <data><Big Title><id=1></data> <da

因此,我试图获得一个UITableView,以按节(thing.title)显示对象列表,但按日期降序列出它们

该表被分为多个部分,这些部分正确地标记为(部分标题是不同的标题)

但每个部分中的对象只正确了一半。每个部分中的对象按降序列出,但某些部分包含应在其他部分中的数据

正在发生的事情的一个例子:

<Header> Big Title Name
    <data><Big Title><id=1></data>
    <data><Big Title><id=4></data>
    **<data><Small Title><id=6></data>**   <-- should not be in this section


<Header> Small Title Name
    <data><Small Title><id=11></data>
    <data><Big Title><id=23></data>  <-- should not be in this section
    **<data><Small Title><id=66></data>**
大标题名称

****用作获取结果控制器的
sectionNameKeyPath
的键和第一个排序描述符中使用的键必须是相同的键或生成相同的相对顺序。因此,不能将sessionTitle用作
sectionNameKeyPath
,而将完全不同的键时间戳用作节的排序描述符

在您的情况下,最好将时间戳用作排序描述符中的
sectionNameKeyPath
。这将确保所有条目正确分组到各个部分

要在节标题中显示sessionTitle而不是时间戳,您可以修改标题ForHeaderSection

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.controller sections] objectAtIndex:section];
    return [[[sectionInfo objects] objectAtIndex:0] sessionTitle];
}
-(NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{
id sectionInfo=[[self.controller sections]objectAtIndex:section];
返回[[[sectionInfo对象]对象索引:0]sessionTitle];
}

在重新加载UITableView之前,请确保根据需要对数组和数组中的对象进行排序。您不需要在cellforRowAtIndexpath中对代码进行任何更改。添加了另一个sortDescriptor,并将其作为描述符数组中的第一个描述符,该描述符可以正常工作。[[NSSortDescriptor alloc]initWithKey:@“sessionTitle”升序:是]@jgervin:好的,那么我稍微误解了你的问题。我以为你想要按日期排序的课程标题。如果我的回答有助于找到正确的解决办法,我会很高兴的。我的数据需要按会话标题进行分区,然后在每个分区中,对象需要按时间戳排序。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.controller sections] objectAtIndex:section];
    return [[[sectionInfo objects] objectAtIndex:0] sessionTitle];
}