对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个数和执行之前的不符,包错。
原因可能有这么几个:
* 你进行了批量操作,删除最后一行数据是用的是:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationF
而不是:
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationF
这样就造成了section的混乱,从而导致该问题。
另一个可能是你没有重写:
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
- (NSInteger)numberOfSectionsInTableV
从而导致执行delete操作以后的datasource个数和执行之前的不符,包错。