具有Custom Cell StoryBoard的IOS SearchDisplayController

时间:2013-11-04 17:17:39

标签: ios iphone objective-c uitableview

我在故事板中有一个单元格原型。所以我自定义了高度,子视图(标签和图像)。 但最终该单元似乎没有用于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;}

我没想法。即使我使用self.tableView而不是tableView,它也显示了这样的东西。 Normal Search Display Controller

2 个答案:

答案 0 :(得分: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 
  }

然后当表视图加载并执行搜索时,searchcontroller的单元格高度和tableview将是相同的。

答案 1 :(得分:0)

您应该使用此方法进行进一步更改,例如:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller  shouldReloadTableForSearchString:(NSString *)searchString
{

[controller.searchResultsTableView setBackgroundColor:[UIColor colorWithRed:0xED/255.0 green:0xED/255.0 blue:0xED/255.0 alpha:1.0]];

controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

return YES;
}
相关问题