[英]IOS SearchDisplayController with Custom Cell StoryBoard
I have a cell prototype in storyboard. 我在情节提要中有一个单元原型。 So I custom the height, subview (Labels and Images).
因此,我自定义了高度,子视图(标签和图像)。 But eventually the cell does not appear to be used for SearchDisplayController... Code snippet >>
但是最终该单元似乎没有用于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;}
I'm out of idea. 我不知道了 Even if I use self.tableView instead of tableView it shows something like this.
即使我使用self.tableView而不是tableView,它也会显示类似的内容。
add the following code before cell for row method. 在行方法的单元格前添加以下代码。
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
tableView.rowHeight = 24.0f; // this should be the same hight as the re usable cell you implemented
}
Then when the table view loads and search is performed the cell hight of the searchcontroller and the tableview would be the same. 然后,当加载表视图并执行搜索时,searchcontroller和tableview的单元格高度将相同。
you should make further changes using this method, for example: 您应该使用此方法进行进一步的更改,例如:
-(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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.