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()中,则会有所帮助。