I'm having difficulty following directions. I have a UISearchBar in a UIView. The user will enter the search string into the UISearchBar and click the search icon to search. The results will display in a new window (UITableView).
My search has shown me this:
A UISearchDisplayController cannot be added to a UIView because it doesn't inherit from a UIView. You can add a UISearchBar in Interface builder with an IBOutlet and then create a UISearchDisplayController with that UISearchBar programmatically.
Just do it in code e.g. (assuming the view controller is vc): [vc addSubview:mySearchDisplayController.searchBar]; // Note that searchBar is the view, and mySearchDisplayController only CONTROLS the searchBar etc.
and also this:
Just make your view controller implement the UISearchBarDelegate. In your xib file, all you need to do is to add a UISearchBar to your view and configure it as necessary, create an outlet for it (optional really but helps to be explicit), and assign the delegate outlet to your view controller. Then, to respond to the search bar events, implement the UISearchBarDelegate protocol methods as necessary. For example: - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [self handleSearch:searchBar]; }
(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { [self handleSearch:searchBar]; }
(void)handleSearch:(UISearchBar *)searchBar { NSLog(@"User searched for %@", searchBar.text); [searchBar resignFirstResponder]; // if you want the keyboard to go away }
(void)searchBarCancelButtonClicked:(UISearchBar *) searchBar { NSLog(@"User canceled search"); [searchBar resignFirstResponder]; // if you want the keyboard to go away }
I'm just not getting it! Should I be adding mySearchController to my UIView? or my UISearchBar? Adding it to my UIView, nothing happens; adding it to my UISearchBar really wigs out the application. I don't even get an error - it just hangs.
Then, there is the second part: The delegate. Should I put the delegate in my UIView? Or in the UISearchDisplayController? Not sure which direction to go in and nothing so far is working. Please help.
All I really want at this point is just to get the handleSearch method to get executed. Thank you very much in advance for any help.
Very confused.