Cannot set searchBar as firstResponder

I noticed this issue too. What seems to happen is the call to becomeFirstResponder is done when the searchController is still ‘loading’. If you comment out becomeFirstResponder you notice that there is no difference. So we need a way to call becomeFirstResponder after the searchController is ‘done’ loading. When I looked at various delegate methods … Read more

How do I use the UISearchBar and UISearchDisplayController

First add the UISearchDisplayController to your table view Then set its delegate. Implement the following methods. Demo Project In your .h File @interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { NSMutableArray *contentList; NSMutableArray *filteredContentList; BOOL isSearching; } @property (strong, nonatomic) IBOutlet UITableView *tblContentList; @property (strong, nonatomic) IBOutlet UISearchBar *searchBar; @property (strong, nonatomic) IBOutlet UISearchDisplayController *searchBarController; In … Read more

How to change the default text of Cancel Button which appears in the UISearchBar +iPhone

Use the appearance proxy: id barButtonAppearanceInSearchBar = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]; [barButtonAppearanceInSearchBar setBackgroundImage:grayBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [barButtonAppearanceInSearchBar setTitleTextAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@”HelveticaNeue-CondensedBold” size:20], NSForegroundColorAttributeName : [UIColor blackColor] } forState:UIControlStateNormal]; [barButtonAppearanceInSearchBar setTitle:@”X”];

Styling the cancel button in a UISearchBar

You can use UIAppearance to style the cancel button without iterating subviews of the UISearchBar, but the UIButton header does not currently have any methods annotated with UI_APPEARANCE_SELECTOR. EDIT: Drill down the subviews till you get that cancel button But this usually returns nil until searchBar.setShowsCancelButton(true, animated: true) is called. extension UISearchBar { var cancelButton … Read more

How to implement UISearchController in UITableView – Swift

Yes, the way search works has been radically changed for what I consider to be a better system. The new system is much better and straight to the point for most simple implementations. Using it is pretty straightforward. First, make your class comply with the UISearchResultsUpdating protocol. class MyTableViewController: UITableViewController, UISearchResultsUpdating {} Add it the … Read more

UISearchBar presented by UISearchController in table header view animates too far when active

Old question but I was able to solve this issue by setting self.extendedLayoutIncludesOpaqueBars = YES; on my view controller. I think is issue is caused by having an opaque navigation bar but setting hidesNavigationBarDuringPresentation to NO on your search controller, causing the search bar to incorrectly position itself when focused.

Displaying search bar in navigation bar in iOS 8

According to Apple : UISearchDisplayController is deprecated in iOS 8. (Note that UISearchDisplayDelegate is also deprecated.) To manage the presentation of a search bar and display search results in iOS 8 and later, instead use UISearchController. The UISearchController class defines an interface that manages the presentation of a search bar in concert with the search … Read more

Smart-search for Parse Usernames in Swift not working

You will want to implement the UISearchResultsUpdating protocol to achieve this. It uses a UISearchController (introduced in iOS 8) which has to be added programmatically instead of through the storyboard, but don’t worry, it’s pretty straight-forward. This should get the job done for you Cheers, Russell class YourTableViewController: UITableViewController, UISearchBarDelegate, UISearchResultsUpdating { var searchUsers: [PFUser] … Read more