Merge pull request #1 from maxDeCod3r/finalTableView

Merge TableView with master checkpoint
This commit is contained in:
maxDeCod3r 2019-05-31 20:28:59 +01:00 committed by GitHub
commit 1aa2a96f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 244 additions and 31 deletions

View File

@ -20,6 +20,8 @@
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 */; };
50C69B1322A19D8800EA99C1 /* NewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C69B1222A19D8800EA99C1 /* NewTableViewCell.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -39,6 +41,8 @@
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 = "<group>"; };
50A9B4E0229E115B00070F61 /* Video.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = Video.mov; sourceTree = "<group>"; };
50C69B1022A16A7100EA99C1 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
50C69B1222A19D8800EA99C1 /* NewTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTableViewCell.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -80,6 +84,8 @@
50A7ADE6229D6C7100D58743 /* Assets.xcassets */,
50A7ADD8229D6A4200D58743 /* Main.storyboard */,
50A7ADFE229D768900D58743 /* MainViewController.swift */,
50C69B1022A16A7100EA99C1 /* TableViewController.swift */,
50C69B1222A19D8800EA99C1 /* NewTableViewCell.swift */,
505AFEF7229FE1BD004FF0F1 /* settingsViewController.swift */,
50A7ADFC229D766800D58743 /* 7_ReadyViewController.swift */,
50A7ADF4229D75A900D58743 /* 3_StartViewController.swift */,
@ -188,8 +194,10 @@
50A7ADFD229D766800D58743 /* 7_ReadyViewController.swift in Sources */,
50A7ADF9229D75C100D58743 /* 5_HandChoiceViewController.swift in Sources */,
50A7ADD7229D6A4200D58743 /* ViewController.swift in Sources */,
50C69B1122A16A7100EA99C1 /* TableViewController.swift in Sources */,
50A7ADF5229D75A900D58743 /* 3_StartViewController.swift in Sources */,
50A7ADD5229D6A4200D58743 /* AppDelegate.swift in Sources */,
50C69B1322A19D8800EA99C1 /* NewTableViewCell.swift in Sources */,
50A7ADFF229D768900D58743 /* MainViewController.swift in Sources */,
50A7ADFB229D75E900D58743 /* 6_SideChoiceViewController.swift in Sources */,
505AFEF8229FE1BD004FF0F1 /* settingsViewController.swift in Sources */,

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>

View File

@ -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 {

View File

@ -300,30 +300,6 @@
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="70" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="402-5S-nhO">
<rect key="frame" x="0.0" y="569" width="414" height="327"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="87K-Xo-0a5">
<rect key="frame" x="0.0" y="28" width="414" height="70"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="87K-Xo-0a5" id="2HV-Qz-1Wd">
<rect key="frame" x="0.0" y="0.0" width="414" height="69.666666666666671"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dkn-bo-t7u">
<rect key="frame" x="20" y="24" width="42" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="Ut7-03-t0b"/>
@ -344,6 +320,80 @@
</objects>
<point key="canvasLocation" x="882.60869565217399" y="776.78571428571422"/>
</scene>
<!--Table View Controller-->
<scene sceneID="UD8-kt-3HT">
<objects>
<viewController storyboardIdentifier="resultsScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="jBr-V0-GbL" customClass="TableViewController" customModule="Guibe" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Rps-Dk-rvQ">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<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="106" width="414" height="790"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="cell" rowHeight="90" id="87K-Xo-0a5" customClass="NewTableViewCell" customModule="Guibe" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="87K-Xo-0a5" id="2HV-Qz-1Wd" customClass="NewTableViewCell" customModule="Guibe" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="89.666666666666671"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9iK-CB-Rc6">
<rect key="frame" x="0.0" y="0.0" width="414" height="90"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<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" 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"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Phone number" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bBb-Ag-DTw">
<rect key="frame" x="20" y="58" width="374" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="primaryLbl" destination="mlZ-q9-9a8" id="Rh6-Gy-EV3"/>
<outlet property="secondaryLbl" destination="bBb-Ag-DTw" id="dQc-es-DNn"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="jBr-V0-GbL" id="wBX-eF-5Hf"/>
<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>
<connections>
<outlet property="tableView" destination="402-5S-nhO" id="Qnx-3U-4Gl"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sgH-Ai-Lho" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="882.60869565217399" y="1484.5982142857142"/>
</scene>
<!--Settings View Controller-->
<scene sceneID="B3S-T4-83q">
<objects>

View File

@ -12,12 +12,20 @@ import MapKit
import CoreLocation
import AVFoundation
class MainViewController: UIViewController, AVAudioPlayerDelegate {
class MainViewController: UIViewController, AVAudioPlayerDelegate, myProtocol {
// DELETE
let defaults = UserDefaults.standard
// DELETE
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let locationManager = CLLocationManager()
var currentCoordinate: CLLocationCoordinate2D!
@ -32,6 +40,7 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
var startedNavigation: Bool = false
var toLocationId: Int = -1
// OUTLETS--------------OUTLETS
@IBOutlet weak var menuWindowView: UIView!
@ -45,7 +54,6 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
@IBOutlet weak var micBtn: UIButton!
// ---------------------
@IBOutlet weak var mapView: MKMapView!
// OUTLETS--------------OUTLETS
// ACTIONS--------------ACTIONS
@ -101,6 +109,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)
@ -124,6 +142,10 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
self.stepCounter += 1
}
}
func startNavigation(toPlace: MKMapItem){
getDirections(to: toPlace)
}
} //END OF CLASS
@ -238,7 +260,6 @@ extension MainViewController: CLLocationManagerDelegate {
extension MainViewController: UISearchBarDelegate {
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("Here2")
searchBar.endEditing(true) //HIDES LE KEYBOARD
let localSearchRequest = MKLocalSearch.Request()
@ -248,14 +269,23 @@ extension MainViewController: UISearchBarDelegate {
let localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.start { (response, _) in
guard let response = response else { return }
guard let firstMapItem = response.mapItems.first else { return }
self.getDirections(to: firstMapItem)
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

@ -0,0 +1,41 @@
//
// NewTableViewCell.swift
// Guibe
//
// Created by Max Hunt on 31/05/2019.
// Copyright © 2019 8. All rights reserved.
//
import UIKit
protocol tableViewProtocol {
func onClickCell(index: Int)
}
class NewTableViewCell: UITableViewCell {
@IBOutlet weak var primaryLbl: UILabel!
@IBOutlet weak var secondaryLbl: UILabel!
@IBAction func goPressed(_ sender: Any) {
cellDelegate?.onClickCell(index: (index?.row)!)
}
var cellDelegate: tableViewProtocol?
var index: IndexPath?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}

View File

@ -0,0 +1,76 @@
//
// 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)
}
}