         
         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


// MARK: - UISearchDisplayDelegate

extension MICountryPicker: UISearchDisplayDelegate {
    
    func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchScope searchOption: Int) -> Bool {
        
        filter(searchDisplayController!.searchBar.text!)
        return true
    }
    
    func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String?) -> Bool {
        filter(searchString!)
        return true
    }
}

    
    private func createSearchBar() {
        if self.tableView.tableHeaderView == nil {
//            let theSearchBar = UISearchBar(frame: CGRectMake(0, 0, 320, 40))
//            theSearchBar.showsCancelButton = true
           
            
            searchController = UISearchController(searchResultsController: nil)
            searchController.searchResultsUpdater = self
            searchController.dimsBackgroundDuringPresentation = false
            tableView.tableHeaderView = searchController.searchBar
        }
    }
    
