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

标签 iphone objective-c cocoa-touch uitableview

这是我想出的:

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

每次我构建和运行时,它都会抛出以下异常:

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.

这有点令人困惑。该部分设置为 1,但异常显示它为 0。

最佳答案

我想通了。

除了前面提到的代码,我还需要对数据源进行更改

[items removeObjectAtIndex:0];

关于iphone - 如何手动删除 UITableView 中的一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/915095/

相关文章:

ios - 为什么我收到控制台警告 : [Process] kill() returned unexpected error 1 when I load a WKWebView in iOS13. 2?

ios - 表格 View 的搜索栏

iphone - 您在 .m 文件顶部添加的 NAMELESS 类别的最佳名称是什么?

iphone - iOS YouTube和类似Safari的电影播放器

ios - 在本地存储远程通知

ios - 线程1 : Fatal error: UnsafeMutablePointer. 初始化重叠范围

objective-c - 如何在iOS应用程序上显示Facebook用户的新闻提要?

objective-c - 键盘出现时向上滑动表格

iphone - 分配,可变到不可变数组?

iPhone编程: Applying Alpha to Parent but not to Child Views