 	override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
 		if segue.identifier == "showParkinglotMap" {
 			let indexPath = tableView.indexPathForSelectedRow()
-			let selectedParkinglot = parkinglots[indexPath!.row]
+
+			let selectedParkinglot: Parkinglot!
+			if searchController.active {
+				selectedParkinglot = filteredParkinglots[indexPath!.row]
+			} else {
+				selectedParkinglot = parkinglots[indexPath!.row]
+			}
+
 			let mapVC: MapViewController = segue.destinationViewController as! MapViewController
 			mapVC.detailParkinglot = selectedParkinglot
 			mapVC.allParkinglots = parkinglots

import UIKit
import CoreLocation

class LotlistViewController: UITableViewController, CLLocationManagerDelegate {

	let locationManager = CLLocationManager()

	// Store the single parking lots once they're retrieved from the server
	// a single subarray for each section
	var parkinglots: [Parkinglot] = []
	var defaultSortedParkinglots: [Parkinglot] = []
	var sectionNames: [String] = []

	override func viewDidLoad() {
		super.viewDidLoad()

		// set CLLocationManager delegate
		locationManager.delegate = self

		stopRefreshUI()
	}

	// /////////////////////////////////////////////////////////////////////////
	// MARK: - UISearchResultsUpdating
	// /////////////////////////////////////////////////////////////////////////

	func updateSearchResultsForSearchController(searchController: UISearchController) {
		let searchString = searchController.searchBar.text

		if searchString == "" {
			filteredParkinglots = parkinglots
		} else {
			filterContentForSearch(searchString)
		}

		tableView.reloadData()
	}

	/**
	Filter the content of the parkinglot list according to what the user types in the searchbar

	:param: searchText String to search with
	*/
	func filterContentForSearch(searchText: String) {
		filteredParkinglots = parkinglots.filter({ (parkinglot: Parkinglot) -> Bool in
			let nameMatch = parkinglot.name.lowercaseString.rangeOfString(searchText.lowercaseString)
			return nameMatch != nil
		})
	}

}
