From ddf3ad28ae62a51dac8dd925589adab1c4af6096 Mon Sep 17 00:00:00 2001 From: Max Hunt Date: Fri, 31 May 2019 17:33:27 +0100 Subject: [PATCH] FIX THIS --- Guibe.xcodeproj/project.pbxproj | 4 +++ Guibe/AppDelegate.swift | 3 ++ Guibe/Base.lproj/Main.storyboard | 49 ++++++++++++++++--------- Guibe/MainViewController.swift | 41 +++++++++------------ Guibe/TableViewController.swift | 62 ++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 40 deletions(-) create mode 100644 Guibe/TableViewController.swift diff --git a/Guibe.xcodeproj/project.pbxproj b/Guibe.xcodeproj/project.pbxproj index cfb466c..e67710f 100644 --- a/Guibe.xcodeproj/project.pbxproj +++ b/Guibe.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 50A7ADFF229D768900D58743 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A7ADFE229D768900D58743 /* MainViewController.swift */; }; 50A7AE02229D7B1100D58743 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50A7AE01229D7B1100D58743 /* MapKit.framework */; }; 50A9B4E1229E115B00070F61 /* Video.mov in Resources */ = {isa = PBXBuildFile; fileRef = 50A9B4E0229E115B00070F61 /* Video.mov */; }; + 50C69B1122A16A7100EA99C1 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C69B1022A16A7100EA99C1 /* TableViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -41,6 +42,7 @@ 50A7AE01229D7B1100D58743 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; 50A7AE05229D7B1E00D58743 /* Guibe.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Guibe.entitlements; sourceTree = ""; }; 50A9B4E0229E115B00070F61 /* Video.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = Video.mov; sourceTree = ""; }; + 50C69B1022A16A7100EA99C1 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -83,6 +85,7 @@ 50A7ADD8229D6A4200D58743 /* Main.storyboard */, 505AFEFB22A154EB004FF0F1 /* TableViewCell.swift */, 50A7ADFE229D768900D58743 /* MainViewController.swift */, + 50C69B1022A16A7100EA99C1 /* TableViewController.swift */, 505AFEF7229FE1BD004FF0F1 /* settingsViewController.swift */, 50A7ADFC229D766800D58743 /* 7_ReadyViewController.swift */, 50A7ADF4229D75A900D58743 /* 3_StartViewController.swift */, @@ -191,6 +194,7 @@ 50A7ADFD229D766800D58743 /* 7_ReadyViewController.swift in Sources */, 50A7ADF9229D75C100D58743 /* 5_HandChoiceViewController.swift in Sources */, 50A7ADD7229D6A4200D58743 /* ViewController.swift in Sources */, + 50C69B1122A16A7100EA99C1 /* TableViewController.swift in Sources */, 505AFEFC22A154EB004FF0F1 /* TableViewCell.swift in Sources */, 50A7ADF5229D75A900D58743 /* 3_StartViewController.swift in Sources */, 50A7ADD5229D6A4200D58743 /* AppDelegate.swift in Sources */, diff --git a/Guibe/AppDelegate.swift b/Guibe/AppDelegate.swift index 2e8172a..dfc8b36 100644 --- a/Guibe/AppDelegate.swift +++ b/Guibe/AppDelegate.swift @@ -7,11 +7,14 @@ // import UIKit +import MapKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + + var navigationResults: MKDirections.Response? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { diff --git a/Guibe/Base.lproj/Main.storyboard b/Guibe/Base.lproj/Main.storyboard index 5c08e8c..d6a1ff5 100644 --- a/Guibe/Base.lproj/Main.storyboard +++ b/Guibe/Base.lproj/Main.storyboard @@ -300,8 +300,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -341,24 +370,12 @@ - + - - - - - - - - - - - - - + - + diff --git a/Guibe/MainViewController.swift b/Guibe/MainViewController.swift index 27e4fff..dd0f086 100644 --- a/Guibe/MainViewController.swift +++ b/Guibe/MainViewController.swift @@ -14,13 +14,13 @@ import AVFoundation class MainViewController: UIViewController, AVAudioPlayerDelegate { - - var testData = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25"] - // DELETE let defaults = UserDefaults.standard // DELETE + let appDelegate = UIApplication.shared.delegate as! AppDelegate + + let locationManager = CLLocationManager() var currentCoordinate: CLLocationCoordinate2D! @@ -105,6 +105,16 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate { let directions = MKDirections(request: directionsRequest) directions.calculate { (response, _) in guard let response = response else { return } + +// self.appDelegate.navigationResults = response + + + +// let resultsViewController = self.storyboard?.instantiateViewController(withIdentifier: "resultsScreen") as! TableViewController +// resultsViewController.searchResults = response +// resultsViewController.modalTransitionStyle = .coverVertical +// self.present(resultsViewController, animated: true, completion: nil) + guard let primaryRoute = response.routes.first else { return } self.mapView.addOverlay(primaryRoute.polyline) @@ -252,6 +262,10 @@ 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) guard let firstMapItem = response.mapItems.first else { return } self.getDirections(to: firstMapItem) } @@ -279,24 +293,3 @@ extension MainViewController: MKMapViewDelegate { return MKOverlayRenderer() } } - - -extension MainViewController: UITableViewDataSource, UITableViewDelegate { - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return testData.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? TableViewCell - cell?.cellLbl.text = testData[indexPath.row] - cell?.cellDelegate = self - cell?.index = indexPath - return cell! - } -} - -extension MainViewController: tableViewProtocol { - func onClickCell(index: Int) { - debugPrint("Pressed on cell number \(index)") - } -} diff --git a/Guibe/TableViewController.swift b/Guibe/TableViewController.swift new file mode 100644 index 0000000..f2cd10d --- /dev/null +++ b/Guibe/TableViewController.swift @@ -0,0 +1,62 @@ +// +// TableViewController.swift +// Guibe +// +// Created by Max Hunt on 31/05/2019. +// Copyright © 2019 8. All rights reserved. +// + +import UIKit +import MapKit + +class TableViewController: UIViewController { + + let appDelegate = UIApplication.shared.delegate as! AppDelegate + + var searchResults: [MKMapItem]? + + override func viewDidLoad() { + super.viewDidLoad() +// let testData = appDelegate.navigationResults + + // Do any additional setup after loading the view. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} + +extension TableViewController: UITableViewDataSource, UITableViewDelegate { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.searchResults?.count ?? 0 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? TableViewCell + let row = indexPath.row + + if let item = searchResults?[row] { + cell?.cellLbl.text = item.name +// cell.phoneLabel.text = item.phoneNumber + } +// cell?.cellLbl.text = self.searchResults[indexPath.row] +// cell?.cellDelegate = self +// cell?.index = indexPath + return cell! + } +} + +extension TableViewController: tableViewProtocol { + func onClickCell(index: Int) { + debugPrint("Pressed on cell number \(index)") + } +}