gpt4 book ai didi

ios - TableView 插入时崩溃

转载 作者:行者123 更新时间:2023-11-29 03:38:30 24 4
gpt4 key购买 nike

尝试插入行时不断收到以下错误:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(0x31fe82a3 0x39ccc97f 0x31f33b75 0x8d18f 0x33fee5a9 0x33edb0c5 0x33edb077 0x33edb055 0x33eda90b 0x33edae01 0x33df9421 0x31fbd6cd 0x31fbb9c1 0x31fbbd17 0x31f2eebd 0x31f2ed49 0x35af62eb 0x33e44301 0xa49d 0x3a103b20)
libc++abi.dylib: terminate called throwing an exception

有人知道这里发生了什么吗?

这是我的代码:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
Caseload *deletedCaseload = [self.caseload objectAtIndex:indexPath.row];
[self.caseload removeObject:deletedCaseload];

[self.caseloadTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else if
(editingStyle == UITableViewCellEditingStyleInsert)
{


Caseload *copiedEntry = [self.caseload objectAtIndex:indexPath.row];
Caseload *newEntry = [[Caseload alloc]init];
newEntry.name = copiedEntry.name;
newEntry.address = copiedEntry.address;
newEntry.phoneNumber = copiedEntry.phoneNumber;
newEntry.identNumber = copiedEntry.identNumber;

[self.caseload addObject:newEntry];
[self.caseloadTableView insertRowsAtIndexPaths:
[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationRight];
}
}

最佳答案

每当您尝试获取 totalIndex + 1 处的数组的对象/值时,就会生成此类错误,例如,如果您的数组具有 4 (确保索引以0开头)并且您尝试获取诸如
之类的值[Myarray objectAtIndex:4] 当时发生了这种类型的错误。

所以最好的原因是使用断点并通过我的建议找出您的问题。

关于ios - TableView 插入时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18800078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com