开发者

Error : Number of Rows In Section in UITableView in iPhone SDK

I am getting this error while I am trying to load the data into my table view.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of 开发者_StackOverflow中文版rows contained in an existing section after the update (73) must be equal to the number of rows contained in that section before the update (71), plus or minus the number of rows inserted or deleted from that section (3 inserted, 0 deleted).

What could be wrong?

Thanks

EDIT :

I am initializing the array on ViewWillAppear and adding new objects to the same array on Tableview's didSelectRowAtIndexPath method

Here is the code On viewWillAppear :

     cellTextArray = [[NSMutableArray alloc] init];

[cellTextArray addObjectsFromArray:newPosts];

Here is the code which modifies the array on didSelectRowAtIndexPath :

       [cellTextArray addObjectsFromArray:newPosts];

       NSMutableArray *insertIndexPaths = [NSMutableArray array];
        for (NSUInteger item = count; item < count + newCount; item++) {

            [insertIndexPaths addObject:[NSIndexPath indexPathForRow:item 
                                                           inSection:0]];
        }

        [self.table beginUpdates];
        [self.table insertRowsAtIndexPaths:insertIndexPaths 
                              withRowAnimation:UITableViewRowAnimationFade];
        [self.table endUpdates];

        [self.table scrollToRowAtIndexPath:indexPath 
                              atScrollPosition:UITableViewScrollPositionNone 
                                      animated:YES];

        NSIndexPath *selected = [self.table indexPathForSelectedRow];
        if (selected) {
            [self.table deselectRowAtIndexPath:selected animated:YES];
        }

Here newPosts is an array which has the values that are added to cellTextArray on didSelectRowAtIndexPath method and viewWillAppear method.


If you have updated the array of data after initialization then you can call this method [yourTable reloadData].

And, it be better if you post the codes here. Then may be some one can help you quickly.


I think, the problem is with the statement in the didSelectRowAtIndexPath method.

You have added the following statement

[self.table insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];

This statement adds the new rows to the table. but the number of rows in the datasource array for that section is different with the number of rows in that section of that table.

So the App is terminated.

Please try by removing the above statement and add required data to the dataSource Array at required indexes and reload the table

Regards,

Satya

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜