加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

对UITableViewController进行更新(增加或删除)

(2014-10-30 18:38:56)
标签:

it

分类: ios
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).'

原因可能有这么几个:

* 你进行了批量操作,删除最后一行数据是用的是:

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];

而不是:

[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] 
withRowAnimation:UITableViewRowAnimationFade];

这样就造成了section的混乱,从而导致该问题。

另一个可能是你没有重写:

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView ;

从而导致执行delete操作以后的datasource个数和执行之前的不符,包错。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有