0
votes

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!

2

2 Answers

4
votes

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/
3
votes

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