部分代码如下,点击后,刷新cell都出错,复用出了问题,请问要怎么设置复用,如何避免这样的问题
static NSString * const defealtSelectCellID = @"applyTransferEstSelectItemCell"; [_tableView registerNib:[UINib nibWithNibName:@"ApplyTransferEstSelectItemCell" bundle:nil] forCellReuseIdentifier:defealtSelectCellID]; -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ switch (indexPath.row) { case 0:{ ApplyTransferEstSelectItemCell *cell = [tableView dequeueReusableCellWithIdentifier:defealtSelectCellID forIndexPath:indexPath]; if (_propertyFollowAllAddEntity.TrustorTypeKeyId) { cell.rightValueLabel.text = _propertyFollowAllAddEntity.TrustorTypeKeyId; }else{ [cell setupLeftTitleWithString:@"*联系人类型" rightLabelString:@"请选择联系人类型"]; } return cell; } case 2:{ ApplyTransferEstSelectItemCell *cell = [tableView dequeueReusableCellWithIdentifier:defealtSelectCellID forIndexPath:indexPath]; if (_propertyFollowAllAddEntity.TrustorGenderKeyId) { cell.rightValueLabel.text = _propertyFollowAllAddEntity.TrustorGenderKeyId; }else{ [cell setupLeftTitleWithString:@"*性别" rightLabelString:@"请选择联系人性别"]; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ _selectedIndexPath = indexPath; switch (indexPath.row) { case 0:{ NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:reloadIndexPath] withRowAnimation:UITableViewRowAnimationNone]; }]; break; } case 2:{ NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:2 inSection:0]; [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:reloadIndexPath] withRowAnimation:UITableViewRowAnimationNone]; }]; break; }
结合cell缓冲池和prepareForReuse方法,可参考博客http://serazheng.github.io/2015-08-15-%E...
要考虑从复用队列找不到cell的情况