         
         let cell: UITableViewCell! = tempCell
         
-        if let searchTableView = searchDisplayController {
-            if tableView == searchTableView.searchResultsTableView {
-                let country = filteredList[indexPath.row]
-                cell.textLabel?.text = country.name
-            } else {
-                let country = sections[indexPath.section].countries[indexPath.row]
-                cell.textLabel?.text = country.name
-            }
+        if searchController.searchBar.isFirstResponder() {
+            let country = filteredList[indexPath.row]
+            cell.textLabel?.text = country.name
         } else {
             let country = sections[indexPath.section].countries[indexPath.row]
             cell.textLabel?.text = country.name

    
    private func createSearchBar() {
        if self.tableView.tableHeaderView == nil {
            let theSearchBar = UISearchBar(frame: CGRectMake(0, 0, 320, 40))
            theSearchBar.showsCancelButton = true
            tableView.tableHeaderView = theSearchBar
            
            searchController = UISearchDisplayController(searchBar: theSearchBar, contentsController: self)
            searchController.delegate = self
            searchController.searchResultsDataSource = self
            searchController.searchResultsDelegate = self
            theSearchBar.becomeFirstResponder()
        }
    }
    


// MARK: - UISearchDisplayDelegate

extension MICountryPicker: UISearchResultsUpdating {
    
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        filter(searchController.searchBar.text!)
        tableView.reloadData()
    }
}
