ios - UItableview 中的多个部分的多项选择

标签 ios objective-c uitableview

如果我选择第一个 indexPath of first section ,所有不同 sections 的第一个 indexPath 都会像图像一样被选中。如何纠正呢?

enter image description here

if ([arraySelectedValue‌​s containsObject:array‌​StateNames[indexPath.‌​row]]) { 
    cell.imageCheck.imag‌​e =[UIImage imageNamed:@"check"]‌​; 
} else { 
    cell.imageCheck.imag‌​e =[UIImage imageNamed:@"uncheck‌​"];
}

最佳答案

将您的代码更改为以下内容。

if ([arraySelectedValue‌​s containsObject:indexPath])
{
    cell.imageCheck.imag‌​e =[UIImage imageNamed:@"check"]‌​;
}
else
{
    cell.imageCheck.imag‌​e =[UIImage imageNamed:@"uncheck‌​"];

}

并在didSelectRow方法中编写以下代码

if ([arraySelectedValues containsObject:indexPath])
{
    [arraySelectedValues removeObject:indexPath];
}
else
{
    [arraySelectedValues addObject:indexPath];

}

并重新加载该部分或行

关于ios - UItableview 中的多个部分的多项选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989593/

相关文章:

objective-c - CATransition 从顶部 curl 页面

ios - 如何使用 MPMediaPickerController 使用单个 UIButton 单击来选择单个歌曲

iphone - 使用 Tesseract OCR 进行汉字识别

iphone - 如何检测 iPhone/iPod Touch/iPad 上活跃的 iTunes 商店?

ios - 如何动画从 TableView (rxswift)中删除单元格?

iphone - 无尽的 UITableview 部分

objective-c - 在 switch 语句中使用 Obj-C 对象时出现奇怪的编译器错误

objective-c - 管理 NSSearchfield 上的键盘事件,无需子类化

ios - EXC_BAD_access code=1 地址 0x NSURLConnection JSON

objective-c - UITableView 阴影