开发者

Getting strange error when reloading section index?

I am using the iPhone SDK and Objective-C and I get this error message:

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:774 2010-01-08 13:24:16.842 MyAPP[628:20b] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).

Here is my code to expand sections:

- (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);
}


The problem is because you're using reloadSections while changing the table's dataSource contents, so that it reports a different number of rows via tableView:numberOfRowsInSection:.

Check what you return from your UITableViewDataSource tableView:numberOfRowsInSection:. My bet is that at the beginning you return 0 for section 1, but when you call reloadSections, you return 1 for section 1.

If this is actually the case, you can use UITableView methods beginUpdates, insertRowsAtIndexPaths:withRowAnimation: and endUpdates.


I had a similar problem. I was sure of being updating the dataSource.

But finally I realized that I was actually modifying 2 sections but updating the dataSource for only one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜