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

Rah*_*yas 2 objective-c uitableview iphone-sdk-3.0 sectionheader

我正在使用iPhone SDKObjective-C,我收到此错误消息:

断言失败 - [UITableView _endCellAnimationsWithContext:],/ SourceCache/UIKit/UIKit-984.38/UITableView.m:774 2010-01-08 13:24:16.842 MyAPP [628:20b]由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第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);
}
Run Code Online (Sandbox Code Playgroud)

Ada*_*Woś 6

问题是因为您在reloadSections更改表的dataSource内容时使用,因此它会通过报告不同的行数tableView:numberOfRowsInSection:.

检查你的回报UITableViewDataSource tableView:numberOfRowsInSection:.我的赌注是,在开头你为第1部分返回0,但是当你打电话时reloadSections,你为第1部分返回1.

如果确实如此,您可以使用UITableView方法beginUpdates,insertRowsAtIndexPaths:withRowAnimation:endUpdates.