views:

1026

answers:

2

I am working on making a search bar above the UITableView, like in the iPod App or Mail app. In the iPod App when you start to type in the search bar the navigation controller disappears and the UISearchBar goes to the top. The animation hasn't been too bad to create, but I want to make sure it behaves exactly like the other search bars in Apple's apps. There are two problems I am having so far:

  1. When I hit "search" on the keyboard or scroll on the tableview the keyboard is dismissed by saying: [searchbar resignFirstResponder];
    This works, except that the cancel button on the searchbar is disabled. How do I keep the searchbar's cancelbutton from disabling itself after the searchbar has resigned first responder?

  2. After the searchbar has lost focus the user should be free to scroll around in the UITableView. Right now the searchbar is added as the tableHeaderView of the UITableView. This means that when the tableview scrolls, the searchbar scrolls right off the screen. Is there a way to make so the searchbar stays at the top of the UITableView and does not scroll? I could not find any property on UITableView that would let the tableHeaderView hover on top.

Any help would be greatly appreciated. Thanks!

+3  A: 

Have a look at SimpleSearchDisplay sample application which comes with the documentation. That's exactly you are looking for. Basically, you dont even have to do explicit animations even. UISearchDisplayController handles it for you.

Here's the location for you.

/Developer/Platforms/iPhoneOS.platform/Developer/Documentation/DocSets/com.apple.adc.documentation.AppleiPhone3_0.iPhoneLibrary.docset/Contents/Resources/Documents/samplecode/SimpleSearchDisplay/
Roshan Amadoru
Thank you so much! I can't believe I didn't see that. I was basing my code off of code that came from a sample application. I wonder why I didn't see UISearchDisplayController back then.
Bridgeyman
sure. no problem :) you are welcome.
Roshan Amadoru
I have SDK 3.1, which doesn't have the SimpleSearchDisplay project. I had Xcocde download the 3.0 docset. I don't see the above project in it. The only projects starting with Simple are SimpleDrillDown and SimpleUndo. Do you have any ideas where I can find SimpleSearchDisplay?
4thSpace
+2  A: 

With SDK 3.1, SimpleSearchDisplay seems to have been replaced by TableSearch:

http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html

or locally:

file:///Developer/Platforms/iPhoneOS.platform/Developer/Documentation/DocSets/com.apple.adc.documentation.AppleiPhone3_1.iPhoneLibrary.docset/Contents/Resources/Documents/samplecode/TableSearch/index.html

Whatcould