代码之家  ›  专栏  ›  技术社区  ›  Rahul Vyas

重新加载节索引时出现奇怪错误?

  •  2
  • Rahul Vyas  · 技术社区  · 15 年前

    我正在使用 iPhone SDK Objective-C 和 我收到此错误消息:

    断言失败-[uitableview\u endcellanimationswithcontext:],/sourcecache/uikit/uikit-984.38/uitableview.m:774 2010-01-08 13:24:16.842 myapp[628:20b]由于未捕获的异常“nsInternalConsistencyException”而终止应用程序,原因:“无效更新:第1节中的行数无效。更新后现有节中包含的行数(1)必须等于更新前该节中包含的行数(0),加上或减去从该节中插入或删除的行数(0插入,0删除)。

    下面是我的代码以展开部分:

    - (void)checkAction:(id)sender
    {
        //The button is added as subview on a view and the view is section header custom view
        UIButton *Button = (UIButton*)sender;
        NSLog(@"Button Tag=%d",Button.tag);
        if([[self.MySectionIndexArray objectAtIndex:Button.tag] isEqualToString:@"UP"])
        {
            [self.MySectionIndexArray replaceObjectAtIndex:Button.tag withObject:@"DOWN"];
            [ButtonDrop setBackgroundImage:[UIImage imageNamed:@"Up.png"] forState:UIControlStateNormal];
            [TableDashBoard reloadSections:[NSIndexSet indexSetWithIndex:Button.tag] withRowAnimation:UITableViewRowAnimationFade];
        }
        else
        {
            [self.MySectionIndexArray replaceObjectAtIndex:Button.tag withObject:@"UP"];
            [ButtonDrop setBackgroundImage:[UIImage imageNamed:@"Down.png"] forState:UIControlStateNormal];
        }
        NSLog(@"self.MySectionIndexArray ka title = %@ at index Number=%d",self.MySectionIndexArray,Button.tag);
    }
    
    2 回复  |  直到 15 年前
        1
  •  6
  •   Adam Woś    15 年前

    问题是因为你在使用 reloadSections 换桌子的时候 dataSource 内容,以便它通过 tableView:numberOfRowsInSection: .

    检查您从 UITableViewDataSource tableview:numberofrowsin部分: . 我敢打赌,在开始的时候你会返回0作为第1部分,但是当你调用 重载区段 ,则返回1作为第1节。

    如果真是这样,你可以用 UITableView 方法 beginUpdates , insertRowsAtIndexPaths:withRowAnimation: endUpdates .

        2
  •  2
  •   Fede Mika    14 年前

    我也有类似的问题。我确信正在更新数据源。

    但最后我意识到我实际上修改了两个部分,但只更新了一个部分的数据源。