Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableViewCell中的复选标记问题_Iphone_Objective C_Cocoa Touch_Uikit - Fatal编程技术网

Iphone UITableViewCell中的复选标记问题

Iphone UITableViewCell中的复选标记问题,iphone,objective-c,cocoa-touch,uikit,Iphone,Objective C,Cocoa Touch,Uikit,我已经实现了下面的代码 UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath]; UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1]; cell.accessoryType = UITableViewCellAccessoryCheckmark; cell2.accessoryType = UITableViewCel

我已经实现了下面的代码

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1];

cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell2.accessoryType = UITableViewCellAccessoryNone;
oldIndexPath1 = indexPath;
但是,如果我选择然后取消选择复选标记,那么我将无法再选择复选标记


你能帮帮我吗?

我想你把支票从一个换到另一个的动作和只换一个单元格的动作搞混了

假设您只需要一个选中标记的单元格,可以执行以下操作:

+(void)toggleCheckmarkedCell:(UITableViewCell *)cell
{
    if (cell.accessoryType == UITableViewCellAccessoryNone)
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    else
        cell.accessoryType = UITableViewCellAccessoryNone;
}

// tableView:didSelectRowAtIndexPath:

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1];

// Toggle new cell
[MyController toggleCheckmarkedCell:cell];
if (cell != cell2) // only toggle old cell if its a different cell
    [MyController toggleCheckmarkedCell:cell2];
oldIndexPath1 = indexPath;

如果您将代码发布在didselectrowatinexpath()中,则会有所帮助。