Search code examples
iphoneuitableviewuisearchbaruisearchdisplaycontroller

Can't get search bar to display in iphone application


I've trying to get a search bar to display in my application.

I'm following the example show in the TableSearch sample application.

I've more or less implemented it exactly the same way apart from the data. I however can never seem to get the actual search bar to display.

The only other difference between my app and the TableSearch app is that mine uses both a tab bar and navigation bar. However I've hacked these into the TableSearch and it still works as expected.

Any suggestions? Anyone else had similar problems to this? This is driving me crazy.

Thanks in advance, Matt


Solution

  • Just to summarise what I was doing wrong and how I fixed it.

    This is what I had previously in my code:

    SearchController *searchController = [[SearchController alloc] initWithNibNamed:nil bundle:nil];
    

    (Note: I have a SearchController.xib too)

    Which seemed to work fine i.e the nib file loaded and worked except the search bar never displayed.

    When I changed the above to:

    SearchController *searchController = [[SearchController alloc] initWithNibNamed:@"SearchController" bundle:nil];
    

    It worked as expected.

    So the lesson to learn from my mistake is - if you're using a nib file - specify it explicitly.

    Hope that helps you, Matt