我通过不同标题的复选标记在 UITableView 中实现过滤器。
根据选定的单元格,查询在本地数据库上运行,我得到一个结果。我将过滤器结果保存在一个数组中,并将这个数组通过 push segue 传递到另一个 uitableviewview 并显示结果。
我正在使用模态搜索进入过滤器屏幕。
但问题是,当我回到过滤器屏幕时,我选择的带有复选标记的单元格的过滤器消失了。
这是我选择行的代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
long sec = [indexPath section];
if(sec==0){
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[sportsSelectedRows addObject:indexPath];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[sportsSelectedRows removeObject:indexPath];
}
}
else if(sec==1){
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[areaSelectedRows addObject:indexPath];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[areaSelectedRows removeObject:indexPath];}
}
else if(sec==2){
cell.tag = indexPath.section;
for (UITableViewCell *cell in [tableView visibleCells]) {
if (cell.accessoryType != UITableViewCellAccessoryNone && cell.tag == indexPath.section) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[daySelectedRows removeAllObjects];
[daySelectedRows addObject:indexPath];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[daySelectedRows removeObject:indexPath];}
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
你能帮忙解决这个问题吗?