删除cell崩溃,数组越界

积累我遇到的问题,求看到的大神给解答下
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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容