您的位置:首页 > 产品设计 > UI/UE

关于UITableView的一个崩溃现象分析

2015-06-03 17:16 127 查看
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:1582

出现这个奔溃的现象原因在下面这行代码中

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}


至于解决办法,参考Stack Overflow的一个回复

To fix it, 
tableView:commitEditingStyle:forRowAtIndexPath:
 needs
to check for the "The user deleted the last row" case and handle it differently. When you're at the last row, you have two options:

Refresh your existing index path (it should transform into the placeholder cell):
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];


Delete the user's cell and insert the placeholder cell:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];


但是自己的还是未解决,因为自己做的是移动cell,有待研究好的方法。如果有知道的大神,求告知。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息