Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First step, create a searchbar with general format and general frame;</p> <pre><code>UISearchBar *mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; [mySearchBar sizeToFit]; // if you give it CGRectZero and sizeToFit, it will shown exactly end of the your navigationBar. mySearchBar.tintColor = [UIColor whiteColor]; mySearchBar.placeholder = @"Search Music"; mySearchBar.showsScopeBar = NO; mySearchDisplayController *mySearchDisplay = [[mySearchDisplayController alloc] mySearchBar contentsController:self]; </code></pre> <p>Then create a new class type of "UISearchDisplayController" as a name "mySearchDisplayController" and as you see, we should merge your searchbar in it 3 lines up. Don't forget implement UITableView protocol to your new class like that;</p> <pre><code>@interface mySearchDisplayController : UISearchDisplayController &lt;UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource&gt; </code></pre> <p>Then in your new mySearchDisplayController class implement that method;</p> <pre><code> -(void)searchDisplayControllerWillBeginSearch:(mySearchDisplayController *)controller { self.searchResultsDataSource = self; self.searchResultsTableView.delegate = self; if (floor(NSFoundationVersionNumber) &gt; 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) &gt; NSFoundationVersionNumber_iOS_6_1) { [UIView animateWithDuration:0.01 animations:^{ for (UIView *subview in self.searchBar.subviews) subview.transform = CGAffineTransformIdentity; }]; } } </code></pre> <p>And last step, you should identify your new frame end of the searchbar to your tableview;</p> <pre><code>- (void)filterContentForSearchText:(NSString*)searchText scope:(NSInteger)scope { [self.filteredSearchResults removeAllObjects]; // First clear the filtered array. for(NSDictionary *searchResult in // your search array) { NSString *searchableString = [NSString stringWithFormat:@"%@ %@", [searchResult objectForKey:@"//your search key"]]; NSRange stringRange = [searchableString rangeOfString:searchText options:NSCaseInsensitiveSearch]; } } [self.searchResultsTableView reloadData]; CGRect screenBound = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBound.size; CGFloat screenHeight = screenSize.height; CGRect frame = self.searchResultsTableView.frame; if (floor(NSFoundationVersionNumber) &lt;= NSFoundationVersionNumber_iOS_6_1) { frame.size.height = screenHeight-64.0f; } else { frame.size.height = screenHeight-44.0f; } self.searchResultsTableView.frame = frame; } </code></pre> <p>I wrote that code 2 months ago for my app and it works perfect for iOS 7 &amp;&amp; 6 &amp;&amp; 5. Hope it works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload