错误:iPhone SDK中UITableView中的部分行数 [英] Error : Number of Rows In Section in UITableView in iPhone SDK

查看:104
本文介绍了错误:iPhone SDK中UITableView中的部分行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试将数据加载到我的表视图时出现此错误。

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

由于未捕获异常终止应用程序'NSInternalInconsistencyException ',reason:'无效更新:第0节中的行数无效。更新后的现有节中包含的行数(73)必须等于更新前该节中包含的行数(71),

可能出现什么问题?

感谢

EDIT

我在ViewWillAppear上初始化数组,并在Tableview的 didSelectRowAtIndexPath 方法

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

这里是代码On viewWillAppear:

     cellTextArray = [[NSMutableArray alloc] init];

[cellTextArray addObjectsFromArray:newPosts];

这里是修改didSelectRowAtIndexPath数组的代码: >

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];
        }

这里 newPosts
didSelectRowAtIndexPath方法和viewWillAppear方法中添加到 cellTextArray

推荐答案

,问题是 didSelectRowAtIndexPath 方法中的语句。

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

您已添加以下语句

[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.

因此应用程序已终止。

请尝试删除上述语句,并将所需数据添加到dataSource数组中所需的索引并重新加载表

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

Satya

这篇关于错误:iPhone SDK中UITableView中的部分行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆