Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios InsertRowsAndExpaths中的内部一致性异常_Ios_Objective C_Uitableview - Fatal编程技术网

Ios InsertRowsAndExpaths中的内部一致性异常

Ios InsertRowsAndExpaths中的内部一致性异常,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在尝试为我的表视图实现insertRowsAtIndexPaths 在这个实现之前,我经常在用户点击表的末尾后调用[self.tableView reloadData]。这种方法有点影响了我的应用程序质量,因为有很多行和很多滚动。(每次重新加载数据前都会冻结) 因此,我使用了以下代码: p.lastid = appRecord.ids; [p main]; dispatch_async(dispatch_get_main_queue(), ^(void) {

我正在尝试为我的表视图实现
insertRowsAtIndexPaths

在这个实现之前,我经常在用户点击表的末尾后调用
[self.tableView reloadData]
。这种方法有点影响了我的应用程序质量,因为有很多行和很多滚动。(每次重新加载数据前都会冻结)

因此,我使用了以下代码:

p.lastid = appRecord.ids;
[p main];
dispatch_async(dispatch_get_main_queue(), ^(void)
        {                                    
         [self.tableView beginUpdates];
         NSArray *temp = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[p.appRecordList count] inSection:0]];
         [self.tableView insertRowsAtIndexPaths:temp withRowAnimation:UITableViewRowAnimationLeft];
         [self.tableView endUpdates];

          });
      });
    }
    return cell;
}
旧的工作守则是:

  NSArray *temp =[self.entries arrayByAddingObjectsFromArray:p.appRecordList];
  self.entries = temp;
  [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
p.appRecordList
是一个
NSArray
,新行项来自hayoola fetch

对于
numberofrowInstition
我使用以下方法:

#define kCustomRowCount     10
@property (nonatomic, assign) int intindex;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSUInteger count = [self.entries count];
    if (count == 0)
    {
        return kCustomRowCount;
    }
    return count;
}
我的代码中也没有
cellforrowatinexpath
。 我应该提到的是,我的程序每次从SERVER r获取10行

这是控制台错误代码:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“尝试将第10行插入节0,但更新后节0中只有10行”*

编辑:(因回答而更改)

将更新方法更改为以下内容后:

[self.tableView beginUpdates];
NSArray *temp_1 =[self.entries arrayByAddingObjectsFromArray:p.appRecordList];
self.entries = temp_1;
NSArray *temp = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[p.appRecordList count] inSection:0]];
[self.tableView insertRowsAtIndexPaths:temp withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
    NSUInteger count = [self.entries count];
    return count;
insertRowsAtIndexPaths

[self.tableView beginUpdates];
NSArray *temp_1 =[self.entries arrayByAddingObjectsFromArray:p.appRecordList];
self.entries = temp_1;
NSArray *temp = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[p.appRecordList count] inSection:0]];
[self.tableView insertRowsAtIndexPaths:temp withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
    NSUInteger count = [self.entries count];
    return count;
出现以下错误:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:节0中的行数无效。”。更新(20)后现有节中包含的行数必须等于更新(10)前该节中包含的行数,加上或减去从该节中插入或删除的行数(插入1行,删除0行),加上或减去移入或移出该节的行数(0迁入,0迁出)。'*


在调用
endUpdates
之前,您需要确保已将其他记录添加到
self.entries
。例外情况是,您尝试添加第11行,但
numberofrowsinssection
返回10

您需要确保插入的行数与添加到数组中的元素数相同

您的更新方法应该是

[self.tableView beginUpdates];

NSMutableArray *newIndices=[NSMutableArray new];

for (id record in p.appRecordList) {
   [self.entries addObject:record];
   [newIndicies addObject:[NSIndexPath indexPathForRow:self.entries.count]];
}


[self.tableView insertRowsAtIndexPaths:newIndices withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];

谢谢你的回答,你能帮助我吗?我可以用什么方式来实现这个目标?我应该如何以及在哪里更新“numberOfRowsInSection”?您的
numberOfRowsInSecfion
返回数组中的条目数,因此如果您更新数组,它应该是正确的-除了数组为空之外,您返回10-为什么要这样做?这意味着您第一次向数组添加内容时,必须插入新行,但如果我只是删除“if”,则删除10个“伪”行(count==0){return kCustomRowCount;}”,那么就不需要修改任何其他内容了?只要您将项目添加到数组中,就不需要了。谢谢您提供的信息,刚刚发生了另一个错误。我正在更新我的问题以了解新的错误