Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Xcode 具有多个NSFetchedResultsController的UITableView导致断言失败_Xcode_Uitableview_Ios_Nsfetchedresultscontroller - Fatal编程技术网

Xcode 具有多个NSFetchedResultsController的UITableView导致断言失败

Xcode 具有多个NSFetchedResultsController的UITableView导致断言失败,xcode,uitableview,ios,nsfetchedresultscontroller,Xcode,Uitableview,Ios,Nsfetchedresultscontroller,我有一个包含3个部分的UITableView,每个部分都通过唯一的NSFetchedResultsController提供 插入、更新…表时,我从NSFetchedResultsController-controllerDidChangeContent获得断言失败 我的猜测是,由于每个控制器只有一个部分(0),所以下面的方法中出现的IndExpath是一个问题,对于第0部分中的控制器,故障不会发生 - (void)controller:(NSFetchedResultsController*)c

我有一个包含3个部分的UITableView,每个部分都通过唯一的NSFetchedResultsController提供

插入、更新…表时,我从NSFetchedResultsController-controllerDidChangeContent获得断言失败

我的猜测是,由于每个控制器只有一个部分(0),所以下面的方法中出现的IndExpath是一个问题,对于第0部分中的控制器,故障不会发生

- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath
{
    switch(type)
    {
        case NSFetchedResultsChangeInsert:
            [[self atableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
            break;
        case NSFetchedResultsChangeDelete:
            [[self atableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
            break;
        case NSFetchedResultsChangeUpdate:
            [self configureCell:(DashboardViewCell *) [[self atableView] cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;
        case NSFetchedResultsChangeMove:
            [[self atableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [[self atableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
    } 
}

所以我的问题是,如何确定正在处理哪个控制器(来自哪个部分)并相应地修改indexath,以及这样做是否正确?以及可能使用多个NSFetchedResultsController和一个uitableview的任何示例。

我不确定它是否是FetchedResultController

insert和delete row调用将在某个时刻要求tableView重新加载,然后要求委托和数据源方法获取numberOfRowsInSection、cellForRowAtIndexPath等

可能发生的情况是模型和tableView不同步,并导致控制器抛出警告

    [tableView beginUpdates];

     if (editingStyle == UITableViewCellEditingStyleDelete) {

        NSMutableDictionary *item = [self.itemList objectAtIndex:indexPath.row];
    // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.itemList removeObjectAtIndex:indexPath.row];      

}   
    [tableView endUpdates];
尝试类似的方法,其中对tableView和底层模型的所有更改都包含在 开始更新和结束更新。这些将导致tableView等待单元格的绘图,直到您给出“OK”

如果上述情况不是这样,那么我通常在tableView中处理多个部分

在标题中,为节声明一个typedef枚举

typedef enum {

    SectionTypeName,
    SectionTypeAge,
    SectionTypeSkills,

} SectionType;

//in the implementation

switch (indexPath.section) {
    case SectionTypeName:
        //do thing in the name section
        break;
    case SectionTypeAge:
        //do thing in the name section
        break;
    case SectionTypeSkills:
        //do thing in the name section
        break;          
    default:
        break;
}
几乎每个tableView委托/数据源方法中都有switch()。
这使我们很容易确定正在处理哪个部分以及它的作用。

我不确定它是否是FetchedResultController

insert和delete row调用将在某个时刻要求tableView重新加载,然后要求委托和数据源方法获取numberOfRowsInSection、cellForRowAtIndexPath等

可能发生的情况是模型和tableView不同步,并导致控制器抛出警告

    [tableView beginUpdates];

     if (editingStyle == UITableViewCellEditingStyleDelete) {

        NSMutableDictionary *item = [self.itemList objectAtIndex:indexPath.row];
    // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.itemList removeObjectAtIndex:indexPath.row];      

}   
    [tableView endUpdates];
尝试类似的方法,其中对tableView和底层模型的所有更改都包含在 开始更新和结束更新。这些将导致tableView等待单元格的绘图,直到您给出“OK”

如果上述情况不是这样,那么我通常在tableView中处理多个部分

在标题中,为节声明一个typedef枚举

typedef enum {

    SectionTypeName,
    SectionTypeAge,
    SectionTypeSkills,

} SectionType;

//in the implementation

switch (indexPath.section) {
    case SectionTypeName:
        //do thing in the name section
        break;
    case SectionTypeAge:
        //do thing in the name section
        break;
    case SectionTypeSkills:
        //do thing in the name section
        break;          
    default:
        break;
}
几乎每个tableView委托/数据源方法中都有switch()。
这使得我们很容易找出正在处理的部分以及它的作用。

因此我的猜测实际上是正确的:

当每个控制器进入以下功能时

  • (void)控制器:(NSFetchedResultsController*)控制器didChangeObject:(id)索引路径中的一个对象:(NSIndexPath*)变更类型的indexPath:(NSFetchedResultsChangeType)类型newIndexPath:(NSIndexPath*)newIndexPath
除了为节0设置的控制器之外,每个控制器的indexPath都不正确

在我的例子中,每个控制器只有一个节-0,但更重要的是,这些节与表节不对应

因此,我目前实现的解决方法(不是很好,所以可能需要返工)是检查控制器的cacheName,并在此基础上修改indexPath/newIndexPath部分

大概是这样的:

if([[controller cacheName] isEqualToString:@"sectionX"])
{
  indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:<add correct section>];
  newIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:<add correct section>];
}
if([[controller cacheName]IsequalString:@“sectionX”])
{
indexPath=[NSIndexPath indexPathForRow:indexPath.row昆虫分类:];
newIndexPath=[NSIndexPath indexPathForRow:indexPath.row昆虫分类:];
}

所以我的猜测是正确的:

当每个控制器进入以下功能时

  • (void)控制器:(NSFetchedResultsController*)控制器didChangeObject:(id)索引路径中的一个对象:(NSIndexPath*)变更类型的indexPath:(NSFetchedResultsChangeType)类型newIndexPath:(NSIndexPath*)newIndexPath
除了为节0设置的控制器之外,每个控制器的indexPath都不正确

在我的例子中,每个控制器只有一个节-0,但更重要的是,这些节与表节不对应

因此,我目前实现的解决方法(不是很好,所以可能需要返工)是检查控制器的cacheName,并在此基础上修改indexPath/newIndexPath部分

大概是这样的:

if([[controller cacheName] isEqualToString:@"sectionX"])
{
  indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:<add correct section>];
  newIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:<add correct section>];
}
if([[controller cacheName]IsequalString:@“sectionX”])
{
indexPath=[NSIndexPath indexPathForRow:indexPath.row昆虫分类:];
newIndexPath=[NSIndexPath indexPathForRow:indexPath.row昆虫分类:];
}
感谢您节省的时间;)
newindepath
的一个小错误。它应该是
[NSIndexPath indexPathForRow:newIndexPath.row inSection:
感谢您节省的时间;)
newindepath
的一个小错误。它应该是
[nsindepath indexPathForRow:newindepath.row-instation: