TABLE VIEW DONEEEE!!!!!

This commit is contained in:
Max Hunt 2019-05-31 20:27:55 +01:00
parent 60cc742779
commit 79cc73fc47
3 changed files with 44 additions and 13 deletions

View File

@ -329,7 +329,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="100" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="402-5S-nhO">
<rect key="frame" x="0.0" y="305" width="414" height="591"/>
<rect key="frame" x="0.0" y="106" width="414" height="790"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
@ -348,7 +348,7 @@
<action selector="goPressed:" destination="87K-Xo-0a5" eventType="touchUpInside" id="fxz-cj-oJk"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mlZ-q9-9a8">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mlZ-q9-9a8">
<rect key="frame" x="20" y="11" width="374" height="39"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
@ -375,6 +375,13 @@
<outlet property="delegate" destination="jBr-V0-GbL" id="JWz-Zv-Onp"/>
</connections>
</tableView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Destinations" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="26H-72-eUL">
<rect key="frame" x="20" y="44" width="235" height="48"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="WeT-3n-RQD"/>

View File

@ -12,7 +12,12 @@ import MapKit
import CoreLocation
import AVFoundation
class MainViewController: UIViewController, AVAudioPlayerDelegate {
class MainViewController: UIViewController, AVAudioPlayerDelegate, myProtocol {
// DELETE
let defaults = UserDefaults.standard
@ -35,6 +40,7 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
var startedNavigation: Bool = false
var toLocationId: Int = -1
// OUTLETS--------------OUTLETS
@IBOutlet weak var menuWindowView: UIView!
@ -48,8 +54,6 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
@IBOutlet weak var micBtn: UIButton!
// ---------------------
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var tableView: UITableView!
// OUTLETS--------------OUTLETS
// ACTIONS--------------ACTIONS
@ -138,6 +142,10 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
self.stepCounter += 1
}
}
func startNavigation(toPlace: MKMapItem){
getDirections(to: toPlace)
}
} //END OF CLASS
@ -261,18 +269,23 @@ extension MainViewController: UISearchBarDelegate {
let localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.start { (response, _) in
guard let response = response else { return }
let resultsViewController = self.storyboard?.instantiateViewController(withIdentifier: "resultsScreen") as! TableViewController
resultsViewController.searchResults = response.mapItems
resultsViewController.modalTransitionStyle = .coverVertical
self.present(resultsViewController, animated: true, completion: nil)
let resultsViewController = self.storyboard?.instantiateViewController(withIdentifier: "resultsScreen") as! TableViewController
resultsViewController.searchResults = response.mapItems
resultsViewController.modalTransitionStyle = .coverVertical
resultsViewController.myProtocol = self
self.present(resultsViewController, animated: true, completion: nil)
// guard let firstMapItem = response.mapItems.first else { return }
// self.getDirections(to: firstMapItem)
}
}
}
extension MainViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolyline {

View File

@ -9,15 +9,24 @@
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
}
@ -60,6 +69,8 @@ extension TableViewController: UITableViewDataSource, UITableViewDelegate {
extension TableViewController: tableViewProtocol {
func onClickCell(index: Int) {
print("Going to navigate to option \(index)")
debugPrint("Going to navigate to option \(index)")
self.myProtocol?.startNavigation(toPlace: (searchResults?[index])!)
self.dismiss(animated: true, completion: nil)
}
}