First step, create a search string with a common format and a common frame;
UISearchBar *mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; [mySearchBar sizeToFit];
Then create a new class type "UISearchDisplayController" as the name "mySearchDisplayController", and, as you can see, we need to combine your search bar 3 lines up. Remember to implement the UITableView protocol for your new class, for example:
@interface mySearchDisplayController : UISearchDisplayController <UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource>
Then, in your new class, mySearchDisplayController implements this method;
-(void)searchDisplayControllerWillBeginSearch:(mySearchDisplayController *)controller { self.searchResultsDataSource = self; self.searchResultsTableView.delegate = self; if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; [UIView animateWithDuration:0.01 animations:^{ for (UIView *subview in self.searchBar.subviews) subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height); }]; } } -(void)searchDisplayControllerWillEndSearch:(mySearchDisplayController *)controller { if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { [UIView animateWithDuration:0.01 animations:^{ for (UIView *subview in self.searchBar.subviews) subview.transform = CGAffineTransformIdentity; }]; } }
And in the last step, you must define your new end to the search box in your table view;
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSInteger)scope { [self.filteredSearchResults removeAllObjects];
I wrote this code 2 months ago for my application, and it works great for iOS 7 && 6 && 5. Hope this works.
source share