 	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

		stopRefreshUI()
	}

}


import UIKit
import CoreLocation

class LotlistViewController: UITableViewController, CLLocationManagerDelegate, UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating {

	let locationManager = CLLocationManager()

	var searchController: UISearchController!

	var parkinglots: [Parkinglot] = []
	var defaultSortedParkinglots: [Parkinglot] = []
	var filteredParkinglots: [Parkinglot] = []
	var sectionNames: [String] = []

	override func viewDidLoad() {
		super.viewDidLoad()

		// Set up the UISearchController
		searchController = UISearchController(searchResultsController: nil)
		searchController.searchResultsUpdater = self
		searchController.searchBar.delegate = self
		searchController.dimsBackgroundDuringPresentation = false
		searchController.hidesNavigationBarDuringPresentation = false
		searchController.searchBar.searchBarStyle = UISearchBarStyle.Minimal

		searchController.searchBar.frame = CGRectMake(searchController.searchBar.frame.origin.x, searchController.searchBar.frame.origin.y, searchController.searchBar.frame.size.width, 44.0)

		tableView.tableHeaderView = searchController.searchBar

		// set CLLocationManager delegate
		locationManager.delegate = self
