Search code examples
iphoneuitableviewios7uisearchbaruisearchdisplaycontroller

search results tableview not displaying the contents of its cells even while filtering of the contents of the table is working fine


i have a viewcontroller containing multiple tableviews managed by the same viewcontroller.i added search to one of the tableviews... i have added the searchbar amd searchisplaycontroller and wired up the outlets for searchdelegate,searchdatasource,searchbar.etc... image showing the views in vc in storyboard

i have the code for filtering the contents of the table working correctly...

below is the code inside the cellforrowatindexpath method

 static NSString *simpleTableIdentifier = @"search";

        SearchFieldsCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

        if (cell == nil) {
            cell = [[SearchFieldsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        }
        NSDictionary *field=nil;


        if (tableView == self.searchDisplayController.searchResultsTableView) {

            field =  _searchfieldsArray[indexPath.row];
        }
        else{
             field = _fieldsArray[indexPath.row];
        }


        cell.titleLabel.text=field[@"a"];
        cell.subtitleLabel.text=field[@"b"];
        cell.detailLabel.text=field[@"c"];



        cell.flagImage.image=[UIImage imageNamed:@"ic_flag.png"];
         return cell;

but its not displaying the contents of the tableview... even the height of the tableviewcell is set and during the runtime... if i give printobject like po cell.titlelabel.text in the debug console it gives result like

<UILabel: 0xc15d500; frame = (70 0; 241 21); text = 'result'; userInteractionEnabled = NO; layer = <CALayer: 0xc15d5b0>>

i further found out that the line of code SearchFieldsCell *cell=[tableViewdequeueReusableCellWithIdentifier:simpleTableIdentifier];

is perfectly working ie loading the prototype cells from the storyboard but the line

if (cell == nil) {
                cell = [[SearchFieldsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
            }

is returning empty white cells somehow its not loading from the prototype cells from the storyboard... how can this happen...?? anyone please help...


Solution

  • i know its not done this way...but after so many different ways the solution was to create a custom xib file and make the uisearchresultscontrollers tableview to register this nib file .it worked

     [self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:@"SearchFieldsCell"
                                                      bundle:[NSBundle mainBundle]]
                forCellReuseIdentifier:@"Search"];