你会觉得这很容易.有了这个代码,我可以检查一个表中的多个行,但是我想要的是只能一次检查一行.如果用户选择不同的行,那么我希望旧行自动取消选中.不知道该怎么做这是我的代码:
- (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.