如何手动删除UITableView中的一行? [英] How to delete a row in UITableView manually?

查看:112
本文介绍了如何手动删除UITableView中的一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想出来的:

  NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:1]; //我的表视图有2节
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];

每次构建和运行时,它都会引发以下异常:


无效更新:部分0中行数无效。更新后现有部分中包含的行数必须等于该部分中包含的行数更新,加或减从该部分添加或删除的行数。


这有点混乱。该部分设置为1,但异常说它为0。

解决方案


$ 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];

这篇关于如何手动删除UITableView中的一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆