UISearchDisplayController显示与原点相同的单元格的最简单方法 [英] Simplest way for UISearchDisplayController to show same cells as the origin
问题描述
使UISearchDisplayController显示与其搜索到的原始tableView完全相同的单元格(格式,高度,字体,颜色等)的最简单方法是什么?或简单地说-使它出列相同的单元格标识符?
What's the simplest way to make UISearchDisplayController display exactly the same cells (formatting, height, fonts, colors, etc) as the original tableView that it searched on? or simply put - make it dequeue de same cell identifier?
我正在使用标准的子类UITableViewController + UISearchDisplayController解决方案,并且希望坚持使用它.
I am using a the standard subclassed UITableViewController + UISearchDisplayController solution, and prefer to stick to it.
谢谢
推荐答案
我实际上找到了最简单的方法.
I actually found the simplest way.
我要做的就是更改默认的cellForRowAtIndexPath第二行代码并添加"self".到tableView到出队单元格标识符-这样,情节提要中的单元格样式总是会出队,而不是searchResultsController.tableView
All I had to do is change the default cellForRowAtIndexPath second line of code and add the "self." to tableView to the dequeue cell identifier - this way the the cell style which is in the storyboard always gets dequeued and not the (non-existant) one from the searchResultsController.tableView
还实现heightForRowAtIndexPath,它将返回相同的高度,而无需进行任何检查(searchresults表或self.table-我们想要相同的高度)
Also implement heightForRowAtIndexPath that will return the same height without any check (searchresults table or self.table - we want the same height)
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 62.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PhraseCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// ^^^^ NEW
//...
这篇关于UISearchDisplayController显示与原点相同的单元格的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!