Simplest way for UISearchDisplayController to show same cells as the origin

落花浮王杯 提交于 2019-12-14 03:09:16

问题


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?

I am using a the standard subclassed UITableViewController + UISearchDisplayController solution, and prefer to stick to it.

thanks


回答1:


I actually found the simplest way.

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

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

    //...


来源:https://stackoverflow.com/questions/11622753/simplest-way-for-uisearchdisplaycontroller-to-show-same-cells-as-the-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!