gpt4 book ai didi

ios - 从 tableview 中删除一行导致崩溃?

转载 作者:行者123 更新时间:2023-11-29 12:13:05 24 4
gpt4 key购买 nike

我有一个 TableView ,它从名为 self.data 的数组中加载数据。然后我试图删除一行,所以首先我将它从数据数组中删除,然后我试图从 TableView 中删除它:

 Data *d=[[Data alloc] init];
[d removeObject:ID];

NSLog(@"%ld",editingRow); //the right row to remove

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:editingRow inSection:0];


//update table
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];

崩溃是这样的:

Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

最佳答案

TableViewDelegate 中尝试以下代码

    [self.tableView beginUpdates];

[d removeObject:ID];

[self.tableView deleteRowsAtIndexPaths:[NSIndexPath indexPathForRow:ID inSection:0]
withRowAnimation:UITableViewRowAnimationRight];

[self.tableView endUpdates];

关于ios - 从 tableview 中删除一行导致崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32795024/

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