- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
StockInListModel *model = self.stockInList[indexPath.row];//崩在这了,因为数组越界
return model.stockInStatus == 2 ? YES : NO;
}
项目里面有左滑删除功能
当有如下操作时,会发生标题描述的情况:
在 indePath为section:0,row:5的 cell左滑出现删除按钮, 在没有关闭编辑状态下,改变数据源 list(count < row + 1),调用[_tableView reloadTableView];
我打断点发现,此时处于编辑状态时reloadTableView,tableView 的代理方法不是先调用
- tableView: numberOfRowsInSection: 和 - tableView: cellForRowAtIndexPath:用当前最新数据源去刷新页面
而是直接调用- tableView: canEditRowAtIndexPath:方法
解决方法:为了避免这种情况发生,在改变了数据源后,要调用[_tableView reloadTableView]之前,先调用[self.tableview setEditing:NO]; 关闭当前编辑状态,就好了
iOS8真的有很多问题,一般出现奇怪的 bug,我就会猜有可能是出在 iOS8手机上。所以我们公司的iOS8系统的测试机 就一直没升级系统