2

I have UITableView and UISearchDisplayController. UITableViewCell is a custom cell with rowHeight = 30:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    UILabel *lbTitle;
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

        lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
        [lbTitle setTag:1];
        [lbTitle setFont:[UIFont fontWithName:@"Sinhala Sangam MN" size:14]];
        //[lbTitle setTextAlignment: NSTextAlignmentCenter];
        [cell addSubview:lbTitle];
    }
    else {
        lbTitle = (UILabel *)[cell viewWithTag:1];
    }
}

How to apply this cell style in UISearchDisplayController. Because when search is "active" UISearchDisplayController's cell looks like basic.

list filtered list

Thanks

SOLVED by the help of MarkM's answer (Is there a way to customize UISearchDisplayController cell):

static NSString *normalCellReuseIdentifier = @"ANormalCell";
static NSString *searchCellReuseIdentifier = @"ASearchCell";

UITableViewCell* cell = nil;
UILabel *lbTitle;
if (tableView != self.searchDisplayController.searchResultsTableView) {
    cell = [tableView dequeueReusableCellWithIdentifier:normalCellReuseIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:normalCellReuseIdentifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

        lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
        [lbTitle setTag:1];
        [lbTitle setFont:[UIFont fontWithName:@"Sinhala Sangam MN" size:14]];
        //[lbTitle setTextAlignment: NSTextAlignmentCenter];
        [cell addSubview:lbTitle];
    }
    else lbTitle = (UILabel *)[cell viewWithTag:1];
} else {
    tableView.rowHeight = 30;
    cell = [tableView dequeueReusableCellWithIdentifier:searchCellReuseIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchCellReuseIdentifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

        lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
        [lbTitle setTag:1];
        [lbTitle setFont:[UIFont fontWithName:@"Sinhala Sangam MN" size:14]];
        //[lbTitle setTextAlignment: NSTextAlignmentCenter];
        [cell addSubview:lbTitle];
    }
    else lbTitle = (UILabel *)[cell viewWithTag:1];
}
Community
  • 1
  • 1
Romowski
  • 1,518
  • 5
  • 25
  • 50
  • Couldn't get it.Can you elaborate more specifically with images – iEinstein May 13 '13 at 10:29
  • left screen is a list of data, and right screen is a filtered list. I need "searchCell"(in the right) looks like cell in the left )) – Romowski May 13 '13 at 10:33
  • http://stackoverflow.com/questions/10620390/is-there-a-way-to-customize-uisearchdisplaycontroller-cell All of the same methods are called. Just compare to searchController.searchResultsTableView – Mark McCorkle May 13 '13 at 10:37
  • Awesome. ;-) I added an answer if you'd like to accept it. – Mark McCorkle May 13 '13 at 12:40

5 Answers5

0

On your instance of UISearchDisplayController (assuming it's called myUISearchDisplayController) call myUISearchDisplayController.searchResultsTableView.rowHeight = 30;

Mike Pollard
  • 10,195
  • 2
  • 37
  • 46
0

When UISearchDisplayController takes control of the table to display the results, it will call

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

To display the cell, so the only thing you have to do is detect when the displayController is calling this method:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isMemberOfClass:[UITableView class]])
    //This is the table view
    else
    //This is the display controller

Do the same with the rest of tghe methods of the delegate/datasource to implemente the search results cells as you want (for example, height or number of rows)

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
0

Search display controller has it's own table in which it shows the data which is searching.You can set the height by using this code-

SDC.searchResultsTableView.rowHeight = 30;//whatever you want 

Where SDC is instance of UISearchDisplayController

iEinstein
  • 2,100
  • 1
  • 21
  • 32
0

All of the same UITableView delegate methods are called with the searchResultsTableView. Please reference the following answer for a more detailed explanation.

Is there a way to customize UISearchDisplayController cell

Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
0

If row height is the only thing to change. setting it with searchResultsTableView.rowHeight works only for the first time. Tapping cancel and search with new search key ignore the custom rowHeight. (iOS 6.1, xcode 4.6.1) use the below.

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
    tableView.rowHeight = 50.0;
}
palaniraja
  • 10,432
  • 5
  • 43
  • 76