ios – UITableView复选框一次只有一行

你会觉得这很容易.有了这个代码,我可以检查一个表中的多个行,但是我想要的是只能一次检查一行.如果用户选择不同的行,那么我希望旧行自动取消选中.不知道该怎么做这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

[tableView deselectRowAtIndexPath:indexPath animated:YES];


UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath];

if (theCell.accessoryType == UITableViewCellAccessoryNone) {
    theCell.accessoryType = UITableViewCellAccessoryCheckmark;
    }

    else if (theCell.accessoryType == UITableViewCellAccessoryCheckmark) {
    theCell.accessoryType = UITableViewCellAccessoryNone;
    }
}

感谢任何帮助,你可以借出!

解决方法

最好的方法是在cellForRowAtIndexPath中设置附件类型,并使用didSelectRowAtIndexPath记录应选择哪个路径,然后调用reloadData.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...