0

2 つの配列を持つビュー コントローラーがあり、1 つは通常の結果用です。もう 1 つは、テキスト入力に基づいてフィルター処理された/検索結果用です。

一度に 1 つのセルだけが UITableViewCellAccessoryCheckmark を持つことができます。

私の問題は次のように説明できます。

いいえ:

  1. View Controller には Venue オブジェクトが供給されます。UITableViewCellAccessoryCheckmark でマークされています。これは予想どおりであり、正しいです。
  2. ユーザーが検索クエリを入力すると、検索結果の配列が使用されます。ただし、UITableViewCellAccessoryCheckmark は、手順 1 で以前にチェックした Venue にはありません。

セルをチェックしない理由がわかりません。

視覚的な例;

元のビュー。Cobo Arena事前に選択された会場です

最初のビュー

-

入力するとき; チェックマークが適切な場所にありません

検索すると結果がフィルタリングされます

-

より多くの入力: チェックマークがなくなりました

より多くのタイピング

-

コードは以下です

- (void) configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    FCVenue *venue;

    if (self.isSearching)
    {
        venue = [self.searchResults objectAtIndex:indexPath.row];
    }
    else
    {
        venue = [self.venues objectAtIndex:indexPath.row];
    }

    if ([indexPath isEqual:self.selectedIndexPath])
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    cell.textLabel.text = [NSString stringWithFormat:@"%@", venue.name];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", venue.location];
}

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView cellForRowAtIndexPath:self.selectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
    self.selectedIndexPath = indexPath;
    [self.tableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    return indexPath;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    FCVenue *venue;

    if (self.searching)
    {
        venue = [self.searchResults objectAtIndex:indexPath.row];
    }
    else
    {
        venue = [self.venues objectAtIndex:indexPath.row];
    }

    self.selectedVenue = venue;

// This method fires a completion block and dismisses the view controller
    if (self.completionBlock)
    {
        self.completionBlock( self, self.selectedVenue );
    }

    [self.navigationController dismissViewControllerAnimated:YES completion:^{
    }];
}
4

1 に答える 1