Ios 滚动时表格视图崩溃

Ios 滚动时表格视图崩溃,ios,ipad,uitableview,uiscrollview,Ios,Ipad,Uitableview,Uiscrollview,我试图使用自定义UITableViewCell构建一个表,但当第一个单元格位于顶部(即隐藏)时滚动时,应用程序收到此错误(EXE\u BAD\u ACCESS(code=1,address=0x14004122))并且应用程序在此崩溃,我从字典中获取数据并将其加载到表视图 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell

我试图使用自定义UITableViewCell构建一个表,但当第一个单元格位于顶部(即隐藏)时滚动时,应用程序收到此错误
(EXE\u BAD\u ACCESS(code=1,address=0x14004122))
并且应用程序在此崩溃,我从字典中获取数据并将其加载到表视图

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    cell = (uploadCustomCell *)[tabelView1 dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellEditingStyleNone];
    if (cell == nil) {
        [[NSBundle mainBundle]loadNibNamed:@"uploadCustomCell" owner:self options:nil];
        cell = (uploadCustomCell  *)self.uploadCustomcell;
    }
    saveBtnCcell.hidden = YES;
    cell.textNamefield.hidden = YES;
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell.defaultSwitch setEnabled:NO];
    NSMutableArray *dictionary = [contents objectAtIndex:indexPath.row];
    NSLog(@"dict dict :%@",dictionary);
    //
    cell.nameLabelCell.text   = [dictionary valueForKey:@"VideoName"];
    cell.userName.text = [dictionary valueForKey:@"User"];
    NSString *defaultVideo = [dictionary valueForKey:@"DefaultVideo"];

    if ([defaultVideo isEqualToString:@"1"]) {
        [cell.defaultSwitch setOn:YES animated:YES];
    }
    else {
        [cell.defaultSwitch setOn:NO animated:YES];
    }

    [cell.defaultSwitch addTarget:self action:@selector(setState:)    forControlEvents:UIControlEventValueChanged];
    cell.thumbImg.image = [arrayimage objectAtIndex:indexPath.row];
    VideoNameTextField.hidden = YES;
    return cell;
}

- (void)setState:(id)sender {
    state = [sender isOn];
       //    NSString *rez = state == YES ? @"YES" : @"NO";
      NSLog(@"state.........:%d",state);
  }

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath     *)indexPath {
    NSLog(@"height:%f",uploadCustomcell.frame.size.height);
    return 207;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSMutableArray *dictionary = [contents objectAtIndex:indexPath.row];
    NSLog(@"Dictionary:%@",dictionary);
    NSLog(@"indexpath:%@",indexPath);
//
    NSLog(@"at index%d obj:%@",indexPath.row,dictionary);
    NSString *nameDetails = [dictionary valueForKey:@"VideoName"];

    guid = [dictionary valueForKey:@"GUID"];

    detailsNameLbl.text = nameDetails;
    detailsVehImg.image = [arrayimage objectAtIndex:indexPath.row];;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:
   (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath    {  
    if (editingStyle == UITableViewCellEditingStyleDelete) {
      [contents removeObjectAtIndex:indexPath.row];
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]     withRowAnimation:UITableViewRowAnimationFade];
    }
}

我认为问题就在这里 替换此行:

cell = (uploadCustomCell *)[tabelView1 dequeueReusableCellWithIdentifier:@"cell"];
通过以下方式:

cell = (uploadCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"];

使用如下代码:

    static NSString *cellIdentifier = @"cell";

    // Try to retrieve from the table view a now-unused cell with the given identifier.
    uploadCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    // If no cell is available, create a new one using the given identifier.
    if (cell == nil)
    {
        NSLog(@"cell allocated");
        // Use the default cell style.

        cell = [[uploadCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"uploadCustomCell"
                                                     owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    // Add your code here
    return cell;
}


希望能对您有所帮助。

请编写错误消息(是数组索引越界错误吗?)这是我获取EXE\u BAD\u访问的错误信息(代码=1,地址=0x14004122)。请格式化您的代码并使其真正可读。再加上添加崩溃日志。此错误发生在哪一行?将断点放在CellForRowatineXpath上,然后检查崩溃在哪一行。即使崩溃,也可能是您试图访问的值Forkey没有值或丢失的原因。即使崩溃,也请输入CellForRowatineXpath中的所有代码,然后检查是否仍然存在崩溃。检查你上传的CustomCell。你做好了吗。你是对的,我在上传自定义类时出错了