如果我选择第一个 indexPath of first section ,所有不同 sections 的第一个 indexPath 都会像图像一样被选中。如何纠正呢?
if ([arraySelectedValues containsObject:arrayStateNames[indexPath.row]]) {
cell.imageCheck.image =[UIImage imageNamed:@"check"];
} else {
cell.imageCheck.image =[UIImage imageNamed:@"uncheck"];
}
最佳答案
将您的代码更改为以下内容。
if ([arraySelectedValues containsObject:indexPath])
{
cell.imageCheck.image =[UIImage imageNamed:@"check"];
}
else
{
cell.imageCheck.image =[UIImage imageNamed:@"uncheck"];
}
并在didSelectRow方法中编写以下代码
if ([arraySelectedValues containsObject:indexPath])
{
[arraySelectedValues removeObject:indexPath];
}
else
{
[arraySelectedValues addObject:indexPath];
}
并重新加载该部分或行
关于ios - UItableview 中的多个部分的多项选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989593/