Search code examples
iosios5delegatesinterface-builderuisearchdisplaycontroller

Changing SearchDisplayController Delegate in interface builder


I'm trying to show a search bar above a table with a list of recent searches that will swap to matching search results once someone enters a search term.

I want to set a custom class MySearchViewController to be the delegate for doing the search and managing the display of search results back to the table so that I can separate the code and not have conditional statements in the default controller.

I've found a bunch of examples that describe how to do this in code but I can't figure out how to do it using Interface Builder.

I've tried dragging a new viewcontroller into my xib and setting the custom class to MySearchViewController and then dragging outlets from the SearchDisplayController as hinted at here: http://goo.gl/RgmwG

I've also tried dragging an Object into the objects column and changing this class to MySearchViewController.

But I feeling completely lost and really just trying things randomly. I'm guessing that I also need to create a property/IBOutlet for the SearchDisplayController somewhere but again lost.

If anyone has a reference to how to go about this I'd be so happy!


Solution

  • Like most problems, it seems pretty obvious in retrospect.

    • Add an 'object' placeholder in interface builder (orange cube).
    • Change the objects custom class to the class you want to be the delegate - e.g. MySearchViewController
    • Remove the default outlets from the standard SearchDisplayContoller to connect with the MySearchViewController object (see screenshot)
    • Make sure that the new delegate has an outlet to a parent view (in my case View)
    • Make sure that the delegate class is initiated from somewhere

      // I did this from the parent ViewConroller, but probably better from the main app delegate?  
      @property (strong, nonatomic) IBOutlet MSSearchViewController *searchViewController;   
      

    Hope this helps someone else who was also stuck!

    Outlets for MySearchViewController