UITableViewCell中的复选标记的问题 [英] Problems with a checkmark in a UITableViewCell

查看:83
本文介绍了UITableViewCell中的复选标记的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了下面的代码。

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

cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell2.accessoryType = UITableViewCellAccessoryNone;
oldIndexPath1 = indexPath;

但是,如果我选择然后取消选中复选标记,那么我不能再选择复选标记。 p>

您能帮我吗?

解决方案



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

  +(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];

//切换新单元格
[MyController toggleCheckmarkedCell:cell];
if(cell!= cell2)//如果不同的单元格,只切换旧单元格
[MyController toggleCheckmarkedCell:cell2];
oldIndexPath1 = indexPath;


I have implemented this below code.

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

cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell2.accessoryType = UITableViewCellAccessoryNone;
oldIndexPath1 = indexPath;

But, if I select and then unselect the checkmark, then I cannot select the checkmark anymore.

can you help me?

解决方案

I think you're confusing the action of changing the check from one to another and the action of toggling one cell only.

Assuming you only want one checkmarked cell, you could do the following:

+(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;

这篇关于UITableViewCell中的复选标记的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆