guide/Guibe/TableViewController.swift
2019-06-03 00:17:29 +01:00

77 lines
2.1 KiB
Swift

//
// TableViewController.swift
// Guibe
//
// Created by Max Hunt on 31/05/2019.
// Copyright © 2019 8. All rights reserved.
//
import UIKit
import MapKit
protocol myProtocol {
func startNavigation(toPlace: MKMapItem)
}
class TableViewController: UIViewController {
var searchResults: [MKMapItem]?
var myProtocol: myProtocol?
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// let testData = appDelegate.navigationResults
}
// func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return searchResults?.count ?? 0
// }
//
// func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// let row = indexPath.row
//
// if let item = searchResults?[row] {
// print(item)
// cell.textLabel?.text = item.name
// }
//
// return cell
// }
} // END OF CLASS
extension TableViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchResults?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! NewTableViewCell
let row = indexPath.row
if let result = searchResults?[row] {
cell.primaryLbl.text = result.name
cell.secondaryLbl.text = result.phoneNumber
cell.cellDelegate = self
cell.index = indexPath
}
return cell
}
}
extension TableViewController: tableViewProtocol {
func onClickCell(index: Int) {
// debugPrint("Going to navigate to option \(index)")
self.myProtocol?.startNavigation(toPlace: (searchResults?[index])!)
self.dismiss(animated: true, completion: nil)
}
}