iOS tableView cell复用出错问题

部分代码如下,点击后,刷新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;
            
        }
阅读 3.6k
2 个回答

要考虑从复用队列找不到cell的情况

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题