Dynamic 动态表中单元格上的UIButton显示错误图像

Dynamic 动态表中单元格上的UIButton显示错误图像,dynamic,uitableview,scroll,uibutton,Dynamic,Uitableview,Scroll,Uibutton,我已经创建了一个带有ui按钮的自定义单元格,用作复选框。按下时,我将按钮图像更改为选中复选框。如果我在滚动其他未选中的单元格时选中任何复选框,则会显示为选中。我猜我是在清除一个标有复选框的单元格,然后重新使用它。我不知道如何正确设置图像。我已经创建了一个图像数组来保存每个按钮的图像状态,但这不起作用。这是我的密码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath

我已经创建了一个带有
ui按钮的自定义单元格,用作复选框。按下时,我将按钮图像更改为选中复选框。如果我在滚动其他未选中的单元格时选中任何复选框,则会显示为选中。我猜我是在清除一个标有复选框的单元格,然后重新使用它。我不知道如何正确设置图像。我已经创建了一个图像数组来保存每个按钮的图像状态,但这不起作用。这是我的密码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Celula de Bebidas";

    MeuChurrasTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.precoTextField.adjustsFontSizeToFitWidth = NO;
    if (indexPath.section == 0) {
        cell.nomeLabel.text = [nomeBebidasAlcoolicas objectAtIndex:indexPath.row]; //nome da bebida
        cell.precoTextField.text = [precoBebidasAlcoolicas objectAtIndex:indexPath.row];
        [cell.checkboxButton setImage:[imagemBebidasAlcoolicasCheckbox objectAtIndex:indexPath.row] forState:UIControlStateNormal];
    } else {
        cell.nomeLabel.text = [nomeBebidasNaoAlcoolicas objectAtIndex:indexPath.row];
        cell.precoTextField.text = [precoBebidasNaoAlcoolicas objectAtIndex:indexPath.row];
        [cell.checkboxButton setImage:[imagemBebidasNaoAlcoolicasCheckbox objectAtIndex:indexPath.row] forState:UIControlStateNormal];
    }
    // identifica cada botao para depois saber qual foi presssionado.
    [cell.checkboxButton setTitle:cell.nomeLabel.text forState:UIControlStateNormal]; 

    return cell;
}
顺便说一下,如果我试一下

if (cell == nil)
由于某种原因,它从不进入if内部,即使是第一次调用表时也是如此

以下是用于设置UIButton图像的代码:

- (void)checkboxPressed:(UIButton *)sender onCell:(MeuChurrasTableViewCell *)cell
{
    NSIndexPath *cellPath = [self.tableView indexPathForCell:cell];
//    NSLog(@"%@ clicked", [nomeBebidasAlcoolicas objectAtIndex:cellPath.row]);
    if ([sender isSelected]) { //Botao nao selecionado
        [sender setImage:unselectedImage forState:UIControlStateNormal];
        [sender setSelected:NO];
        [self.brain.bebidasSelecionadas removeObject:sender.titleLabel.text];
        if (cellPath.section == 0)
            [imagemBebidasAlcoolicasCheckbox insertObject:unselectedImage atIndex:cellPath.row];
        else
            [imagemBebidasNaoAlcoolicasCheckbox insertObject:unselectedImage atIndex:cellPath.row];            
    } else { //Botao selecionado
        [sender setImage:selectedImage forState:UIControlStateSelected];
        [sender setSelected:YES];
        [self.brain.bebidasSelecionadas addObject:sender.titleLabel.text];
        if (cellPath.section == 0)
            [imagemBebidasAlcoolicasCheckbox insertObject:selectedImage atIndex:cellPath.row];
        else
            [imagemBebidasNaoAlcoolicasCheckbox insertObject:selectedImage atIndex:cellPath.row];
    }
}
有什么帮助吗