Having trouble implementing updateSearchResultsForSearchController in UISearchController? - ios

I'm having a difficult time trying to implement updateSearchResultsForSearchController in a UISearchController. It has to do with how I implemented my original array. I'm not sure how to use that array to find the searched text.
Here's a snippet of my code:
Test.swift:
struct Test
{
let name: String
let hobby: String
}
Main.swift:
var resultsSearchController = UISearchController()
var filteredData: [Test] = [Test]()
var data: [Test] = [Test]()
override func viewDidLoad()
{
resultsSearchController = UISearchController(searchResultsController: nil)
definesPresentationContext = true
resultsSearchController.dimsBackgroundDuringPresentation = true
resultsSearchController.searchResultsUpdater = self
tableView.tableHeaderView = resultsSearchController.searchBar
data = [
Test(name: "Abby", hobby: "Games"),
Test(name: "Brian", hobby: "TV"),
Test(name: "Ced", hobby: "Gym"),
Test(name: "David", hobby: "Fun")]
tableView.dataSource = self
tableView.delegate = self
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
if (resultsSearchController.active && resultsSearchController.searchBar.text != "")
{
return filteredData.count
}
return data.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell: UITableViewCell!
// Dequeue the cell to load data
cell = tableView.dequeueReusableCellWithIdentifier("Funny", forIndexPath: indexPath)
let example: Test
if resultsSearchController.active && resultsSearchController.searchBar.text != ""
{
example = filteredData[indexPath.row]
}
else
{
example = data[indexPath.row]
}
return cell
}
func updateSearchResultsForSearchController(searchController: UISearchController)
{
filteredData.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "hobby CONTAINS[c] %#", resultsSearchController.searchBar.text!)
// WHAT ELSE TO DO?
tableView.reloadData()
}
I'm just a bit confused on how to use my data to return back the correct searched results in updateSearchResultsForSearchController.
Can someone point me in the right direction?
Thanks

What do you need to to is make the search in your data source and return the data nothing else, something like this code:
func updateSearchResultsForSearchController(searchController: UISearchController) {
filteredData.removeAll(keepCapacity: false)
let searchedData = resultsSearchController.searchBar.text
// find elements that contains the searchedData string for example
filteredData = data.filter { $0.name.containsString(searchedData) }
tableView.reloadData()
}
If you want to perform another type of search regarding another field of your struct you can modify the filter like you like. Once you call the tableView.reloadData() all is going to be reloaded again.
I hope this help you.

Related

table view does not reload after delete letter in search bar

I am trying to search contact in my app. I am using search bar to do that.
Lets suppose that I have a 2 contacts, Tolga and Toygun. When I type for "To" in searchbar both contact appears in table view. Then I type for "Toy" in searchbar no one appears in table view as should be. The problem is when I delete the letter y in "Toy" no one continues to appear. I want to see both contact in table view when I delete letter y but I couldn't.
Here is my code:
class ContactsVC: UIViewController {
//MARK: - Proporties
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var searchBar: UISearchBar!
#IBOutlet weak var emptyView: UIView!
let fireStoreDatabase = Firestore.firestore()
var contactArray = [Contact]()
var tempContactArray = [Contact]()
var letters: [Character] = []
var tempLetters: [Character] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
searchBar.delegate = self
hideKeyboardWhenTappedAround()
getDataFromFirebase()
}
//MARK: - Function to Get Contacts Data From Firebase
func getDataFromFirebase(){
fireStoreDatabase.collection("Contacts").order(by: "contactName").addSnapshotListener { (snapshot, err) in
if err == nil {
if snapshot?.isEmpty == false && snapshot != nil {
self.contactArray.removeAll(keepingCapacity: false)
for document in snapshot!.documents {
if let uid = document.get("uid") as? String {
if uid == self.userId {
if let contactUrl = document.get("contactUrl") as? String,
let contactName = document.get("contactName") as? String,
let contactSirname = document.get("contactSirname") as? String,
let contactPhone = document.get("contactPhone") as? String,
let contactEmail = document.get("contactEmail") as? String,
let contactBloodgroup = document.get("contactBloodGroup") as? String,
let contactBirthday = document.get("contactBirthday") as? String{
self.contactArray.append(Contact(contactUrl: contactUrl, contactName: contactName, contactSirname: contactSirname, contactPhone: contactPhone, contactEmail: contactEmail, contactBloodgroup: contactBloodgroup, contactBirthday: contactBirthday, documentId: document.documentID))
}
}
}
}
self.tempContactArray = self.contactArray
//Section
self.letters.removeAll(keepingCapacity: false)
self.letters = self.contactArray.map({ (contact) in
return contact.contactName.uppercased().first!
})
self.letters = self.letters.sorted()
self.letters = self.letters.reduce([], { (list, name) -> [Character] in
if !list.contains(name) {
return list + [name]
}
return list
})
self.tempLetters = self.letters
self.tableView.reloadData()
} else {
self.contactArray.removeAll(keepingCapacity: false)
self.tableView.reloadData()
}
if(self.contactArray.count == 0) {
self.emptyView.isHidden = false
self.tableView.isHidden = true
}else{
self.emptyView.isHidden = true
self.tableView.isHidden = false
}
}
}
}
//MARK: - Section after search
func getLetters(contact: [Contact]) {
letters.removeAll(keepingCapacity: false)
letters = contact.map({ (contact) in
return contact.contactName.uppercased().first!
})
letters = letters.sorted()
letters = letters.reduce([], { (list, name) -> [Character] in
if !list.contains(name) {
return list + [name]
}
return list
})
}
//MARK: - Table View Data Source
extension ContactsVC: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
letters.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return letters[section].description
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contactArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ContactsViewCell
if letters[indexPath.section] == contactArray[indexPath.row].contactName.uppercased().first {
cell.contactImage.sd_setImage(with: URL(string: contactArray[indexPath.row].contactUrl))
cell.contactFullNameLabel.text = contactArray[indexPath.row].contactName + " " + contactArray[indexPath.row].contactSirname
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if letters[indexPath.section] == contactArray[indexPath.row].contactName.uppercased().first {
return 100.0
} else {
return 0.0
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(identifier: "AddContactVC") as! AddContactVC
vc.isNewContact = false
vc.documentId = contactArray[indexPath.row].documentId
vc.contact = contactArray[indexPath.row]
self.present(vc, animated: true, completion: nil)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
view.endEditing(true)
}
}
//MARK: - Search Bar
extension ContactsVC: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
print(searchText)
letters.removeAll(keepingCapacity: false)
if searchText.isEmpty == false {
contactArray = contactArray.filter{$0.contactName.lowercased().contains(searchText.lowercased())}
getLetters(contact: contactArray)
} else {
contactArray = tempContactArray
letters = tempLetters
}
self.tableView.reloadData()
}
}
This line causes the problem.
contactArray = contactArray.filter{$0.contactName.lowercased().contains(searchText.lowercased())}
let's consider the same example you mentioned. You have two contacts 'Tolgo' and 'Toygun'. When you type 'To', You filter the contacts and again assign it to the contactArray. So now contactArray will have two contacts Tolgo and Toygun. When you type 'Toy', again you apply filter on those 2 contacts in contactArray and assign to contactArray again. Now you will have only one contact detail 'Toygun' in contactArray. You are deleting 'y' from 'toy' search keyword, now you apply filter on contactArray which only has one contact(toygun). This causes only one contact to show in table
Solution:
Have all your fetched contacts in contactArray. On searching, filter from this array and assign the filtered items to tempContactArray. Have tempContactArray as the source array.
I hope i am able to help you solve your problem.
You can also implement UISearchController UISearchResultsUpdating protocol with function updateSearchResults and handle all your changes there. Here is a smooth tutorial: https://www.raywenderlich.com/4363809-uisearchcontroller-tutorial-getting-started

searching and filter array firebase data swift3

My app crashing while search a text in a searchbar with error: thread1:signal SIGABRT probably the problem updateSearchResults() method?
or type of array? I'm beginner with swift any idea?
#IBOutlet weak var tableView: UITableView!
var data = [Any]()
var ref:FIRDatabaseReference!
// Filter Data from Firebase
var filteredData = [Any]()
// Declare searchBar
let searchController = UISearchController(searchResultsController: nil)
//is the device landscape or portrait
var isPortraid = true
#IBOutlet weak var bannerView: GADBannerView!
func fetchDataFromFirebase(){
EZLoadingActivity.show("caricamento...", disableUI: true)
ref = FIRDatabase.database().reference()
ref.observe(.value, with: { (snapshot) in
let dataDict = snapshot.value as! NSDictionary
self.data = dataDict["data"] as! [Any]
self.filteredData = self.data
print ("Sacco di merda:\(self.filteredData)")
self.tableView.reloadData()
EZLoadingActivity.hide()
})
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
fetchDataFromFirebase()
// Implement searchBar
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
NotificationCenter.default.addObserver(self, selector: #selector(MainViewController.orientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
//TableView Data Source and Delegate
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filteredData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MainCell", for:indexPath) as! MainScreenTableViewCell
let rowData = self.filteredData[indexPath.row] as! NSDictionary
let imageName = rowData["imageName"] as! String
cell.backgroundImageView.image = UIImage(named: imageName)
let label = rowData["categoryName"] as! String
cell.mealCategoryLabel.text = label
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let categoryViewController = storyboard.instantiateViewController(withIdentifier: "CategoryViewController") as! CategoryViewController
let rowData = self.data[indexPath.row] as! NSDictionary
categoryViewController.categoryTitle = rowData["categoryName"] as! String
let categoryData = rowData["category"] as! [Any]
categoryViewController.data = categoryData
self.navigationController?.pushViewController(categoryViewController, animated: true)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if isPortraid {
return UIScreen.main.bounds.height/3
} else {
return UIScreen.main.bounds.height/1.2
}
}
//Method for update search
func updateSearchResults(for searchController: UISearchController) {
if searchController.searchBar.text! == ""{
filteredData = data
} else {
filteredData = data.filter{($0 as AnyObject).contains(searchController.searchBar.text!)}
}
self.tableView.reloadData()
}
if searchController.searchBar.text! == ""
This is almost certainly the offender. The text property on UI objects is typically nil when it's empty, so when you force unwrap it your app crashes. You should never force unwrap something unless you are absolutely certain it will never be nil at that point.
There's a couple different ways you can handle this, which basically amount to making sure text isn't nil before you do anything with it.
Personally I would rewrite the if statement to unwrap the optional for the non-empty case:
if let text = searchController.searchBar.text, text != "" {
filteredData = data.filter{($0 as AnyObject).contains(text)}
} else {
filteredData = data
}
You could also use nil-coalescing:
if (searchController.searchBar.text ?? "") == ""
but personally I prefer to write it to avoid force unwrapping even when you're sure it isn't nil, so I would recommend the first one.

filtering and displaying searchbar results from firebase database

I am just starting to learn swift and firebase. I want to add a search bar that will allow users to search through my firebase database. This is what I want to get
I have added the searchbar, what I'm having problem with is the display of search result.
I created a container view that include Name, subdescription and logo like the image above and then set them up with this function
func searchResultContainer(){
searchResultView.addSubview(businesslogoView)
searchResultView.addSubview(businessNameLabel)
searchResultView.addSubview(businessSectorLabel)
//need x. y, width, height constraints for searchResult
searchResultView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
searchResultView.topAnchor.constraint(equalTo: view.topAnchor, constant: 100).isActive = true
searchResultView.heightAnchor.constraint(equalToConstant: 220).isActive = true
}
I then append the searchResult view to var bussinesarray. and then insert it into the tableview. Please see my code below
var businessArray = [NSDictionary]()
var filterBusiness = [NSDictionary]()
var ref : FIRDatabaseReference!
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.insertRows(at: [IndexPath(row: self.businessArray.count-1, section: 0)], with: UITableViewRowAnimation.automatic)
ref.child("Businesses").queryOrdered(byChild: "Basic-Info/business").observe(.childAdded, with: { (snapshot) in
view.addSubview(searchResultView)
searchResultContainer()
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// if searchbar is not empty "", then return filtered businesses if the user is not typing anything return all businesses.
if searchController.isActive && searchController.searchBar.text !=
""{
return filterBusiness.count
}
return self.businessArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let business : NSDictionary?
if searchController.isActive && searchController.searchBar.text !=
""{
business = filterBusiness[indexPath.row]
}
else
{
business = self.businessArray[indexPath.row]
}
cell.textLabel?.text = business?["Business"] as? String
cell.detailTextLabel?.text = business?["handle"] as? String
return cell
}
func filterContent (searchText:String) {
self.filterBusiness = self.businessArray.filter{ Businesses in
let businessName = Businesses["Business"] as? String
return(businessName?.contains(searchText.lowercased()))!
}
tableView.reloadData()
}
func updateSearchResults(for searchController: UISearchController) {
// update the search results
filterContent(searchText: self.searchController.searchBar.text!)
}
I am not getting the search result from firebase DB, how do I correctly implement the search result from firebase DB? I am building everything programmatically, please a sample code with be greatly appreciated.
This tutorial was a great help for me in figuring out a similar implementation, see the code near the bottom of the tutorial.
http://shrikar.com/swift-ios-tutorial-uisearchbar-and-uisearchbardelegate/
Code adjustments beyond this tutorial included the below code. I still have some clean up that could be done around the if/else section however the two critical concepts for me was using the model and getting the target correct with: let temp: NSString = text.EntityName! as NSString
Model file:
class Dealer: NSObject{
var DealerNumber: String?
var EntityName: String?
//matchup all other firebase data fields
}
ViewController Adjustments
var dealerList = [Dealer]()
var filterDealers = [Dealer]()
---
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
filterDealers = dealerList.filter({ (text) -> Bool in
let temp: NSString = text.EntityName! as NSString
let range = temp.range(of: searchText, options: NSString.CompareOptions.caseInsensitive)
return range.location != NSNotFound
})
if(filterDealers.count == 0){
searchActive = false;
} else {
searchActive = true;
}
refreshTable()
}
----
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
var cell:UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
if(searchActive){
cell?.textLabel?.text = filterDealers[indexPath.row].EntityName
cell?.detailTextLabel?.text = filterDealers[indexPath.row].DealerNumber
} else {
cell?.textLabel?.text = dealerList[indexPath.row].EntityName
cell?.detailTextLabel?.text = dealerList[indexPath.row].DealerNumber
}
return cell!;
}

Search Bar controller in TableView

Hello I am trying to implement a SearchBarController but If I type something in the search bar data doesn't comes up according to the letters typed. Here is my code
class CountriesTableViewController: UITableViewController, UISearchResultsUpdating {
var dict = NSDictionary()
var filterTableData = NSDictionary()
var resultSearchController = UISearchController()
override func viewDidLoad() {
super.viewDidLoad()
getCountriesNamesFromServer()
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
self.tableView.reloadData()
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(self.resultSearchController.active){
return self.filterTableData.count-1
}else {
return dict.count-1
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CountriesTableViewCell
if(self.resultSearchController.active){
// (cell.contentView.viewWithTag(1) as! UILabel).text = filterTableData[indexPath.row]
cell.countryNameLabel.text = (((filterTableData["\(indexPath.item)"] as?NSDictionary)!["Countries"] as?NSDictionary)!["name"] as?NSString)! as String
return cell
}else{
cell.countryNameLabel.text = (((dict["\(indexPath.item)"] as?NSDictionary)!["Countries"] as?NSDictionary)!["name"] as?NSString)! as String
return cell
}
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
let keys: NSArray = dict.allKeys
let filteredKeys: [String] = keys.filteredArrayUsingPredicate(NSPredicate(format: "SELF CONTAINS[c] %#", searchController.searchBar.text!)) as! [String]
filterTableData = dict.dictionaryWithValuesForKeys(filteredKeys)
}
I think Problem is in this function updateSearchResultsForSearchController because first I think I have to remove the object from Nsdictionary. I know in Array we do this
filterTableData.removeAll(keepCapacity: false)
and I think for NSDictionary I have to use NSMUtableDictionary But I don't know if that is the problem. If it is the problem still don't know how can I remove objects from NSMutableDictionary and in short to make this search functionality workable.
Note: Data is Populating successfully in tableView.. just the search functionality is not working

UISearchBarController "works", but doesn't display on screen

I have a CoreData project written in Swift that I've added a UISearchController to. I set breakpoints to see if the search is working and I can print out a list of filteredObjects from lldb in the console, but they don't display on the view.
Basically, the cells in my app load fine when the the searchBar isn't in use, but the moment I type something in the searchBar, I've verified the searchPredicate's being set and objects are being added to my filteredObjects array, but I can't figure out why they're not going on the screen. I think my problem "lives" here:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
if searchPredicate == nil {
self.configureCell(cell, atIndexPath: indexPath)
} else {
// configure the cell based on filteredObjects data
if let note = self.filteredObjects?[indexPath.row] {
cell.textLabel?.text = note.noteTitle
}
return cell
}
If there's no predicate, it's cellForRowAtIndexPath is returning what it finds in the managedObjectContext. If there IS a searchPredicate, I need to return a the info from the Note object in the filteredObjects array from the searchResultsController.
I think I know "what" I need to do, but I don't know the "how" part. I'm having trouble figuring out how to do this. Thanks for reading. If you've got any ideas, I would be grateful.
Here's my Note object:
class Note: NSManagedObject {
#NSManaged var dateCreated: NSDate
#NSManaged var dateEdited: NSDate
#NSManaged var noteTitle: String
#NSManaged var noteBody: String
}
Another potential "problem area" could be my configureCell method:
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as! NSManagedObject
cell.textLabel!.text = object.valueForKey("noteTitle")!.description
}
I've got the numberOfRowsInSection set here:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.searchPredicate == nil {
let sectionInfo = self.fetchedResultsController.sections![section] as! NSFetchedResultsSectionInfo
return sectionInfo.numberOfObjects
} else {
return filteredObjects?.count ?? 0
}
}
Here are the relevant properties I've got setup and the viewDidLoad:
class MasterViewController: UITableViewController,
NSFetchedResultsControllerDelegate, UISearchControllerDelegate,
UISearchResultsUpdating, UISearchBarDelegate
// Properties
var detailViewController: DetailViewController? = nil
var managedObjectContext: NSManagedObjectContext? = nil
// Properties for UISearchController
var searchController: UISearchController!
var searchPredicate: NSPredicate?
var filteredObjects : [Note]? = nil
Here's my viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = self.editButtonItem()
if let split = self.splitViewController {
let controllers = split.viewControllers
let context = self.fetchedResultsController.managedObjectContext
let entity = self.fetchedResultsController.fetchRequest.entity!
self.detailViewController = controllers[controllers.count-1].topViewController as? DetailViewController
}
// UISearchController setup
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.searchBar.sizeToFit()
self.tableView.tableHeaderView = searchController?.searchBar
self.tableView.delegate = self
self.definesPresentationContext = true
}
This delegate method gets called when the search bar's text the search bar becomes first responder.
// MARK: - UISearchResultsUpdating Delegate Method
func updateSearchResultsForSearchController(searchController: UISearchController) {
let searchText = self.searchController?.searchBar.text // steve put breakpoint
println(searchController.searchBar.text)
if let searchText = searchText {
searchPredicate = NSPredicate(format: "noteBody contains[c] %#", searchText)
filteredObjects = self.fetchedResultsController.fetchedObjects?.filter() {
return self.searchPredicate!.evaluateWithObject($0)
} as! [Note]?
self.tableView.reloadData()
println(searchPredicate)
}
}
When the searchBar is cancelled, everything goes back to normal when I use this delegate method to set the searchPredicate & filteredObjects back to nil
// MARK: - UISearchBar Delegate methods
func searchBar(searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
updateSearchResultsForSearchController(self.searchController)
}
func didDismissSearchController(searchController: UISearchController) {
println("didDismissSearchController")
self.searchPredicate = nil
self.filteredObjects = nil
self.tableView.reloadData()
}

Resources