积累我遇到的问题,求看到的大神给解答下
1.删除cell崩溃(数组越界)
/*想知道[_iTableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationBottom];//这个会报错
[_iTableView reloadData];
这俩方法到底有啥区别*/
NSDictionary *addDic = self.addressAry[indexPath.section];//错在这,感觉是数组越界(只有一个cell时),
[HNAddressManger postDeleteWithDIc:nil success:^(NSDictionary *info) {
NSLog(@"111%@",info);
if ([info[@"ret"] intValue] == 200) {
NSDictionary * data = info[@"data"];
if ([[data[@"code"] stringValue] isEqualToString:@"1"]) {
NSDictionary *smallData = data[@"data"];
if ([[smallData[@"Result"] stringValue] isEqualToString:@"1"]) {
[self.addressAry removeObjectAtIndex:indexPath.section];
// [_iTableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationBottom];//这个会报错
[_iTableView reloadData];//换成他就好了
}
}
}else
{
}
} fail:^(NSError *error) {
NSLog(@"000%@",error);
}];
16.10.21更
差点忘了回来看下,
是 [_iTableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] 中的indexPath 已经更新了,所以越界,在使用前要通过cell重新生成indexPath.
功夫不负有心人
// __weak typeof (cell)weakCell = cell;
NSIndexPath * newIndexPath = [tableView indexPathForCell:weakCell];
DLog(@"dian ji le %ld",newIndexPath.row);
DLog(@"删数剧院%ld",indexPath.row);
[weakSelf.dataAry removeObjectAtIndex:newIndexPath.row];
[tableView deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];