0

ストーリーボードにセル プロトタイプがあります。そこで、高さ、サブビュー (ラベルと画像) をカスタマイズします。しかし、最終的にセルは SearchDisplayController に使用されていないようです... コード スニペット >>

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
#warning Reusable cell not working for custom cell.
ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:itemCell];

if (cell == nil) {
    cell = [[ItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:itemCell];
}

if (tableView == self.searchDisplayController.searchResultsTableView){
    cell.itemLabel.text = [_filteredList objectAtIndex:indexPath.row];
    cell.priceLabel.text = @"RM 7.00";
    // TODO : Insert Image Here
} else {
    cell.itemLabel.text = [_items objectAtIndex:indexPath.row];
    cell.priceLabel.text = @"RM 7.00";
    // TODO : Insert Image Here
}

return cell;}

わからない。tableView の代わりに self.tableView を使用しても、次のように表示されます。 普通 検索表示コントローラー

4

2 に答える 2

1

行メソッドのセルの前に次のコードを追加します。

 - (void)searchDisplayController:(UISearchDisplayController *)controller  didLoadSearchResultsTableView:(UITableView *)tableView
 {
tableView.rowHeight = 24.0f; // this should be the same hight as the re usable cell you implemented 
  }

次に、テーブルビューがロードされて検索が実行されると、検索コントローラーとテーブルビューのセルの高さが同じになります。

于 2013-11-04T19:23:25.353 に答える