1

I'm currently learning iOS development. Unfortunately the course I've signed up for is based on iOS 7 and doesn't seem to have any support. I have Xcode 7 however and have become very stuck on trying to implement a search bar in a table view. I've been searching for answers on how to fix the 'searchDisplayController' deprecation, and while there is information out there, being new to Objective-C, I haven't worked out how to fix my issue.

I have a very basic TableView app that simply displays the months of the year in a TableView. I've added the "Search Bar and Search Display Controller" to the TableView. Here is the first part of my code where Xcode tells me that 'searchDisplayController' is deprecated within 'TableViewController.m':

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // Return the number of rows in the section.
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [_filteredResults count];
    }
    else {
       return [_monthsOfTheYear count];
    }
}

I would really appreciate it if someone could let me know what I need to do instead or to point me to a tutorial that could help me to understand it.

Thank you!

Seosup
  • 11
  • 1
  • 3

3 Answers3

2

You are looking for UISearchController. You may go through Apple Documentation for this. Here is one good tutorial on this. You may also look into this SO post. And this video would also add into your knowledge base.

Community
  • 1
  • 1
Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • I've had a look through all these tutorials and links you posted but I still can't get my head around it. I also need to program this using Objective-C so the Swift video didn't help unfortunately. Do I need to add the "UISearchController" to my header file, i.e. in my code, I currently have: "@interface TableViewController : UITableViewController" - so do I need to add UISearchController in here? – Seosup Oct 31 '15 at 10:10
0

UISearchController replaces UISearchDisplayController. Here is a tutorial re: how to use it.

Adrian
  • 16,233
  • 18
  • 112
  • 180
0

add this Property

let searchController = UISearchController(searchResultsController: nil) 

and add this code in your viewDidLoad

searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
yourTableView.tableHeaderView = searchController.searchBar
yourTableView.contentOffset = CGPoint(x: 0, y: searchController.searchBar.frame.height)

for more detail check this tutorial for swift and this tutorial

Chetan
  • 881
  • 14
  • 22