0

さまざまなタイトル見出しのチェックマークを使用して、UITableView にフィルターを実装しています。

選択したセルによると、ローカルデータベースでクエリが実行され、結果が得られます。フィルター結果を配列に保存し、この配列をプッシュセグエを介して別の 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];
}

これを解決するのを手伝ってもらえますか。

4

1 に答える 1

0

内部didSelectRowAtIndexPath:では、アイテム/パスが現在選択されているか選択されていないという事実を記録する以外は何もしません。アクセサリ ハンドリングを に移動しますcellForRowAtIndexPath:

于 2015-01-19T18:57:54.897 に答える