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

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

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

iOS 11 customise search bar in navigation bar

I just found out how to set also the rest of them: (with some help of Brandon, thanks!) The “Cancel” text: searchController.searchBar.tintColor = .white The search icon: searchController.searchBar.setImage(UIImage(named: “my_search_icon”), for: UISearchBarIcon.search, state: .normal) The clear icon: searchController.searchBar.setImage(UIImage(named: “my_search_icon”), for: UISearchBarIcon.clear, state: .normal) The search text: UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white] Thanks for the help @Brandon! … Read more

Light gray background in “bounce area” of a UITableView

Setting transparencies is bad for performance. What you want is the gray area above the search bar, but it should still be white beyond the end of the list. You can add a subview to your UITableView that lives above the content instead. CGRect frame = self.list.bounds; frame.origin.y = -frame.size.height; UIView* grayView = [[UIView alloc] … 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.

UISearchBar text color change in iOS 7

In iOS 7 to access Text Field you have to reiterate on level more. Change your code like this for (UIView *subView in self.searchBar.subviews) { for (UIView *secondLevelSubview in subView.subviews){ if ([secondLevelSubview isKindOfClass:[UITextField class]]) { UITextField *searchBarTextField = (UITextField *)secondLevelSubview; //set font color here searchBarTextField.textColor = [UIColor blackColor]; break; } } } Note : This … Read more

Cannot change search bar background color

Like @aliamcami, all the answers before did not work as I would expect, either the answer did not work for me or it works but it needs too much “dummy” code. So I share another answer wrote in Swift 4 with simplified logic: for textField in searchController.searchBar.subviews.first!.subviews where textField is UITextField { textField.subviews.first?.backgroundColor = .white … Read more