Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 尝试在表视图中按日期对核心数据对象排序_Ios_Objective C_Iphone_Uitableview_Core Data - Fatal编程技术网

Ios 尝试在表视图中按日期对核心数据对象排序

Ios 尝试在表视图中按日期对核心数据对象排序,ios,objective-c,iphone,uitableview,core-data,Ios,Objective C,Iphone,Uitableview,Core Data,我有一个核心数据设置,其中每个对象都有一个NSDate和一个以字符串形式返回日期的方法(即“12/15/2009”)。这些对象显示在一个表视图中,我想根据日期字符串将它们分为多个部分。CoreDataBooks应用程序中的苹果示例代码使用以下行: NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest

我有一个核心数据设置,其中每个对象都有一个NSDate和一个以字符串形式返回日期的方法(即“12/15/2009”)。这些对象显示在一个表视图中,我想根据日期字符串将它们分为多个部分。CoreDataBooks应用程序中的苹果示例代码使用以下行:

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"author" cacheName:@"Root"];
所以我修改了它,并在我的项目中使用了这一行:

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"workoutDateString" cacheName:@"Root"];
其中,“workoutDateString”是以字符串形式返回训练对象日期的方法。当我将sectionNameKeyPath保留为nil时,我的核心数据设置工作得非常好,而且我还知道我的workoutDateString方法工作正常。但是,当我将sectionNameKeyPath设置为workoutDateString时,它不仅不会显示节标题,而且每次添加训练对象时,程序都会因以下错误而崩溃:

由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:节1中的行数无效。”。更新(3)后现有节中包含的行数必须等于更新(1)前该节中包含的行数,加上或减去从该节中插入或删除的行数(插入0,删除0)。'


这是我第一个真正的iPhone项目,我没有任何设置表格部分的经验。相信我,我花了相当多的时间在谷歌上寻找解决方案。

我遇到了完全相同的问题,并且花了大量的时间研究它

NSFetchedResultsControllerDelegate“animate changes”代码会在将项目添加到全新分区或将某个分区中的所有项目移动到另一个分区时导致严重问题,使原始分区保留0个项目

我要么删除所有插入/删除节/行的代码,要么使用Jeff LaMarche的代码来修复它

编辑:您实现了[tableView:TitleForHeaderSection],对吗

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[<#Fetched results controller#> sections] objectAtIndex:section];
    return [sectionInfo name];
}
-(NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{
id sectionInfo=[[sections]objectAtIndex:section];
返回[sectionInfo name];
}

我遇到了完全相同的问题,并花了大量时间研究它

NSFetchedResultsControllerDelegate“animate changes”代码会在将项目添加到全新分区或将某个分区中的所有项目移动到另一个分区时导致严重问题,使原始分区保留0个项目

我要么删除所有插入/删除节/行的代码,要么使用Jeff LaMarche的代码来修复它

编辑:您实现了[tableView:TitleForHeaderSection],对吗

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[<#Fetched results controller#> sections] objectAtIndex:section];
    return [sectionInfo name];
}
-(NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{
id sectionInfo=[[sections]objectAtIndex:section];
返回[sectionInfo name];
}

我添加了Jeff LaMarche的代码和tableView:titleForHeaderInSection方法,现在应用程序在启动时崩溃:**由于未捕获的异常“NSRangeException”而终止应用程序,原因:'***-[NSCFArray objectAtIndex:::]:索引(0)超出边界(0)\\开始调试的时间到了,这两段代码都是“已知良好”的,在进一步学习NSFetchedResultsController之前,您应该阅读《表视图编程指南》。如果您没有很好地掌握表视图(即缺少titleForHeaderInstruction之类的内容),那么几乎不可能使用NSFetchedResultsController。啊哈,我刚刚错误地实现了titleForHeaderInstruction方法。非常感谢。我添加了Jeff LaMarche的代码和tableView:TitleForHeaderInstruction方法,现在应用程序在启动时崩溃:**由于未捕获的异常“NSRangeException”终止应用程序,原因:“***-[NSCFArray objectAtIndex::]:索引(0)超出边界(0)u调试时间到了,这两段代码都是“已知良好”的,在进一步学习NSFetchedResultsController之前,您应该阅读《表视图编程指南》。如果您没有很好地掌握表视图(即缺少titleForHeaderInstruction之类的内容),那么几乎不可能使用NSFetchedResultsController。啊哈,我刚刚错误地实现了titleForHeaderInstruction方法。非常感谢。