Iphone UItableView上的多个NsfetchedResultsController

Iphone UItableView上的多个NsfetchedResultsController,iphone,uitableview,nsmutablearray,nsfetchedresultscontroller,Iphone,Uitableview,Nsmutablearray,Nsfetchedresultscontroller,在表视图中实现2nsfetchedresultsController时遇到困难。我希望在表的每个部分(2个部分)中都有一个fetchedresultsController,类似这样: 愿望列表 产品 产品2 购买 产品3 我知道,对于这个示例,我不需要2个nsfetchedResultsController,但稍后我会需要这个 当我从一个nsfetchedResultsController中删除一个产品时,它会传递到另一个,我得到以下错误: 无效更新:节0中的行数无效。人数 必须删除更新

表视图中实现2
nsfetchedresultsController
时遇到困难。我希望在表的每个部分(2个部分)中都有一个fetchedresultsController,类似这样:

愿望列表

  • 产品
  • 产品2
购买

  • 产品3
我知道,对于这个示例,我不需要2个nsfetchedResultsController,但稍后我会需要这个

当我从一个nsfetchedResultsController中删除一个产品时,它会传递到另一个,我得到以下错误:

无效更新:节0中的行数无效。人数 必须删除更新(0)后现有节中包含的行 等于该节中包含的行数,在 更新(0),加上或减去从中插入或删除的行数 该部分(插入1,删除0)。带有用户信息(空)”

我认为这是因为当第一个fetchedRController检测到更改时,它会在调用第二个之前更新tableView,对吗?我应该使用NSMutableArray并手动更新tableView吗?

守则:

-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
NSInteger numberOfRows=0;
道岔(区段)
{
案例愿望列表部分:
{
numberOfRows=[[fetchedResultsControllerwish fetchedObjects]计数];
};
打破
个案组:
{   
numberOfRows=[[FetchedResultsController购买的FetchedObject]计数];
};
打破
违约:
打破
}
返回numberOfRows;
}
-(void)controllerWillChangeContent:(NSFetchedResultsController*)控制器{
//fetch控制器即将开始发送更改通知,因此请准备表视图以进行更新。
[self.tableView开始更新];
}
-(void)controllerDidChangeContent:(NSFetchedResultsController*)控制器
{
//fetch控制器已发送所有当前更改通知,因此请告诉表视图处理所有更新。
[self.tableView endUpdates];
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeObject:(id)一个对象
atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)类型
newindepath:(nsindepath*)newindepath{
UITableView*tableViewT=self.tableView;
开关(类型){
案例NSFetchedResultsChangesInsert:
[tableViewT insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
打破
案例NSFetchedResultsChangeDelete:
[tableViewT deleteRowsatindExpath:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
打破
案例NSFetchedResultsChangeUpdate:
[self-configureCell:[GiftEventTableViewCell*)[tableViewT cellForRowAtIndexPath:indexPath]atIndexPath:indexPath];
打破
案例NSFetchedResultsChangeMove:
[tableViewT deleteRowsatindExpath:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[tableViewT insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
打破
}
}
-(void)configureCell:(GiftEventTableViewCell*)单元格atIndexPath:(NSIndexPath*)indexPath
{
开关(indexPath.section){
案例愿望列表部分:
{
GiftEvent*giftEv=(GiftEvent*)[fetchedResultsControllerwish objectAtIndexPath:indexPath];
cell.gift=giftEv;
};
打破
个案组:
{
GiftEvent*giftEv=(GiftEvent*)[fetchedResultsControllerPurchased objectAtIndexPath:indexPath];
//如果在第二节中不使用indexpath.row,则会出现越界错误
//GiftEvent*giftEv=(GiftEvent*)[[FetchedResultsController购买的FetchedObject]objectAtIndex:indexPath.row];
cell.gift=giftEv;
};
打破
违约:
打破
}
}
//替代以支持编辑表格视图。
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径{
如果(editingStyle==UITableViewCellEditingStyleDelete)
{
开关(indexPath.section){
案例愿望列表部分:
{
//删除给定索引路径的托管对象
[self.managedObjectContext deleteObject:[fetchedResultsControllerwish objectAtIndexPath:indexPath];
//保存上下文。
n错误*错误;
如果(![self.managedObjectContext保存:&错误]){
/*
将此实现替换为适当处理错误的代码。
abort()导致应用程序生成崩溃日志并终止。您不应在装运应用程序中使用此函数,尽管它在开发过程中可能很有用。如果无法从错误中恢复,请显示一个警告面板,指示用户通过按“主页”按钮退出应用程序。
*/
NSLog(@“未解决的错误%@,%@”,错误,[error userInfo]);
中止();
}
[self.tableView重载数据];
};
打破
个案组:
{
//删除给定索引路径的托管对象
[self.managedObjectContext deleteObject:[fetchedResultsControllerPurchased objectAtIndexPath:indexPath];
//保存上下文。
n错误*错误;
如果(![self.managedObjectContext保存:&错误]){
/*
将此实现替换为适当处理错误的代码。
abort()导致应用程序生成崩溃日志并终止。您不应在装运应用程序中使用此函数