使附件类型成为所选单元格的复选标记

时间:2015-02-17 16:58:38

标签: ios objective-c uitableview didselectrowatindexpath accessorytype

我试图让所选的单元格(自定义UITableViewCell)对其进行复选标记。我尝试了以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CategorieCell *customCell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];

    if (customCell.accessoryType == UITableViewCellAccessoryDisclosureIndicator) {
        customCell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        customCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
}

但是当我选择一个细胞时,没有任何事情发生。

1 个答案:

答案 0 :(得分:2)

您的错误在于您将新的自定义单元格出列。相反,您必须找出实际选择的单元格。将第一行更改为:

CategorieCell *customCell = (CategorieCell *)[tableView cellForRowAtIndexPath:indexPath];

这应该是它。

相关问题