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.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...