tags:

views:

87

answers:

2

This is a followup to this question: http://stackoverflow.com/questions/2770330/uinavigationcontroller-uitableview-uisearchbar-uisplitviewcontroller

Is there any way to make it so the solution above doesn't make it unfilter the results? In my case you see the entire list pop back up (during the animation) when you deactivate the search in viewWillDisappear, and if you do it in viewDidDisappear then it seems to be too late and the next view is once again below/ontop of the bar. Any other solution?

A: 

OK, I've got your answer-

Here are the steps that worked for me [containing some pseudocode]:

1) Since you are searching you are most certainly already overriding ShouldReloadForSearch- So just add piece of code that saves/stores the forSeachString.

2) This one may vary quite a bit depending on your app- but the gist for this step is that you need to clear out the stored search string [set to null] if no search results are loaded. I did this in my UITableViewSource. I have 2 constructors- one for the full dataset and another on for the filtered [search results] dataset. So I just set it to null in my full dataset constructor. Yeah, you could do it differently no doubt but that's how I did it.

3) Next, do as the original "answer" states and call SetActive - [self.searchDisplayController setActive:NO];. They advocated doing it in override of ViewDidAppear. I didn't do that... I did this immediately after I pushed the next UIViewController in my RowSelected override.

4) Last, within your UIViewController that has the UISearchDisplayController attached- check for your saved search string and if it exists then do the following: 1) call SetActive again BUT this time with a true parameter ie setActive:YES... then 2) set the searchBar text to your saved search string value. I did this in the ViewWillAppear override.

Long story short... this worked for me AND it maintains the search results. Setting the searchBar text in step 4 is the key... this effectively gets the filter to persist.

Hope this helps someone

Pimp Juice McJones