有没有办法自定义UISearchDisplayController单元格

我正在使用UISearchDisplayController进行search,并希望将更多的元素添加到每个单元格,如果可能的话。 做了一些search,但没有find任何信息。 唯一的办法是用tableview来重现它。 有没有其他的属性,我可以设置其他textlabel.text

提前致谢!

是的,你可以设置cell.imageView,cell.accessoryView,cell.BackGroundView ..等

请阅读此UITableViewCell文档以获取更多信息

您可以完全更改单元格。

以下片段依赖于UITableCell的两个子类,ANormalCell&ASeCeCell。

警告:这个代码还没有编译,但你得到的要点?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *normalCellReuseIdentifier = @"ANormalCell"; static NSString *searchCellReuseIdentifier = @"ASearchCell"; UITableViewCell* cell = nil; if (tableView != self.searchDisplayController.searchResultsTableView) { cell = (ANormalCell*)[self.tableView dequeueReusableCellWithIdentifier:normalCellReuseIdentifier]; if (cell == nil) { NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ANormalCell" owner:nil options:nil]; cell = (ANormalCell*)[topLevelObjects objectAtIndex:0]; } } else { cell = (ASearchCell*)[self.tableView dequeueReusableCellWithIdentifier:searchCellReuseIdentifier]; if (cell == nil) { NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ASearchCell" owner:nil options:nil]; cell = (ASearchCell*)[topLevelObjects objectAtIndex:0]; } } return cell; } 

很可能。 所有的tableView数据源方法都使用tableView参数来调用。 如果

 if (tableView == searchController.searchResultsTableView) 

然后通过添加子视图或自定义属性来更改单元格。 在这种情况下,同样的方法适用于自定义单元格。