14

Xcode 4.2 を使用して、ストーリーボード ベースの iOS アプリケーションを作成しました。画面の 1 つに、動的なカスタム セルを使用する UITableViewController が含まれています。

ここまでは順調ですね。

ここで、UISearchDisplayController を追加して、リストをフィルタリングできるようにしたいと考えました。

何らかの理由で、UISearchDisplayController にカスタム セルが表示されず、強制する方法が見つかりません...

これが私の cellForRowAtIndexPath メソッドの外観です。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"QueueListCell";
    QueueListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[QueueListTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                             reuseIdentifier:CellIdentifier];
    }
    assert(cell);

    if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {
        indexPath = [_indexPathsForSearchResults objectAtIndex:indexPath.row];
    }

    // Set up the cell...
    NSDictionary* itemDict = [_ListItems objectAtIndex:indexPath.row];

    cell.labelQueueName.text = [itemDict objectForKey:kQueueName];
    cell.labelQueueNumItems.text = [[itemDict objectForKey:kQueueNumItems] stringValue];

    return cell;    
}

これを機能させる方法について何か考えはありますか?つまり、私の UISearchDisplayController テーブルには正しい数の結果が表示されます (それらをクリックできるので、何をクリックしているかを知らせるために NSLog を追加したことはわかっています...)

これは私のテーブルビューです これは私のテーブルビューです

検索表示テーブルはこんな感じ・・・ 検索表示テーブルはこんな感じ・・・

私の問題/質問は、UISearchDisplayController テーブル ビューにカスタム セルを表示する方法です。

助けていただければ幸いです...

ルーヴェン

4

1 に答える 1

27

クエリ固有の回答

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}

完全な例については、Apple のサイトからサンプル コードを入手してください。

ステップ バイ ステップの図

于 2011-12-07T12:50:36.287 に答える