且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何手动删除UITableView中的一行?

更新时间:2023-02-07 09:10:08


$ b

除了上述代码,我还需要更改数据源



  items removeObjectAtIndex:0]; 


Here's what I've come up with:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1]; // my table view has 2 sections
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];

Everytime I build and run, it throws the following exception:

Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update must be equal to the number of rows contained in that section before the update, plus or minus the number of rows added or removed from that section.

It's a bit confusing. The section is set to 1, yet the exception says it's 0.

I figured it out.

In addition to the aforementioned code, I also need to make changes to the datasource

[items removeObjectAtIndex:0];