更新时间:2023-02-13 14:13:16
在数据源中,我更新了第4节取决于中的行数第3节.从中删除行时第3节,第4节中的行数从0到1.这似乎导致问题.有没有办法避免这个吗?
In datasource, I update section 4 depending on the number of rows in section 3. When a row is deleted from section 3, number of rows in section 4 goes from 0 to 1. This seems to cause the issue. Is there no way to avoid this?
使用 deleteRowsAtIndexPaths:withAnimation
时,您保证数据源将只删除具有指定索引路径的行.在您的情况下,您还将在表中插入一行,这意味着数据源的状态与表视图所期望的状态不同.
When using deleteRowsAtIndexPaths:withAnimation
you are guaranteeing that the data source will have removed just the rows with the specified index paths. In your case you are also inserting a row into the table which means that state of the data source is not what the table view expects.
在第3节中删除一行还涉及在第4节中插入一行时,您必须执行以下操作:
When deleting a row in section 3 that also involves inserting a row in section 4 you must do something like:
[self.tableView beginUpdates];
[self.tableView [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPath:[NSArray arrayWithObject:indexPathForInsertedRow] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];