Skip to content

Commit

Permalink
begin implementing master view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikoles committed Aug 10, 2017
1 parent 4b83c53 commit d1086a9
Show file tree
Hide file tree
Showing 34 changed files with 4,282 additions and 320 deletions.
6 changes: 6 additions & 0 deletions CarsTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
96124D9D1F3C8873004D68AE /* CarTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96124D9C1F3C8873004D68AE /* CarTableViewCell.swift */; };
96474A381F3C6BA200317B8B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96474A371F3C6BA200317B8B /* AppDelegate.swift */; };
96474A3A1F3C6BA200317B8B /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96474A391F3C6BA200317B8B /* MasterViewController.swift */; };
96474A3C1F3C6BA200317B8B /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96474A3B1F3C6BA200317B8B /* DetailViewController.swift */; };
Expand All @@ -20,6 +21,7 @@

/* Begin PBXFileReference section */
26D7E8C34FA75D08C3D02163 /* Pods-CarsTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CarsTest.release.xcconfig"; path = "Pods/Target Support Files/Pods-CarsTest/Pods-CarsTest.release.xcconfig"; sourceTree = "<group>"; };
96124D9C1F3C8873004D68AE /* CarTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CarTableViewCell.swift; sourceTree = "<group>"; };
96474A341F3C6BA200317B8B /* CarsTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CarsTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
96474A371F3C6BA200317B8B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96474A391F3C6BA200317B8B /* MasterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -85,6 +87,7 @@
96474A451F3C6BA300317B8B /* Info.plist */,
969550C81F3C6CA2008F015A /* Networking.swift */,
969550CC1F3C6DBB008F015A /* Car.swift */,
96124D9C1F3C8873004D68AE /* CarTableViewCell.swift */,
);
path = CarsTest;
sourceTree = "<group>";
Expand Down Expand Up @@ -192,11 +195,13 @@
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CarsTest/Pods-CarsTest-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/AlamofireImage/AlamofireImage.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AlamofireImage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -231,6 +236,7 @@
files = (
96474A3C1F3C6BA200317B8B /* DetailViewController.swift in Sources */,
96474A3A1F3C6BA200317B8B /* MasterViewController.swift in Sources */,
96124D9D1F3C8873004D68AE /* CarTableViewCell.swift in Sources */,
969550CD1F3C6DBB008F015A /* Car.swift in Sources */,
96474A381F3C6BA200317B8B /* AppDelegate.swift in Sources */,
969550C91F3C6CA2008F015A /* Networking.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion CarsTest/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false }
if topAsDetailController.detailItem == nil {
if topAsDetailController.car == nil {
// Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return true
}
Expand Down
59 changes: 42 additions & 17 deletions CarsTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<device id="retina4_0" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -10,6 +15,7 @@
<objects>
<navigationController title="Master" id="RMx-3f-FxP" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="Pmd-2v-anx">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand All @@ -23,16 +29,17 @@
<!--Detail-->
<scene sceneID="yUG-lL-AsK">
<objects>
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailViewController" customModule="CarsTest" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="SYR-Wa-9uf"/>
<viewControllerLayoutGuide type="bottom" id="GAO-Cl-Wes"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="svH-Pt-448">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Detail view content goes here" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="0XM-y9-sOw">
<rect key="frame" x="20" y="275.5" width="280" height="17"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" size="system"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand Down Expand Up @@ -73,30 +80,44 @@
<!--Master-->
<scene sceneID="smW-Zh-WAh">
<objects>
<tableViewController title="Master" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="r7i-6Z-zg0">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<tableViewController title="Master" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="CarsTest" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="80" sectionHeaderHeight="22" sectionFooterHeight="22" id="r7i-6Z-zg0">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="Arm-wq-HPj" style="IBUITableViewCellStyleDefault" id="WCw-Qf-5nD">
<frame key="frameInset" minY="86" width="375" height="44"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="CarTableViewCell" id="WCw-Qf-5nD" customClass="CarTableViewCell" customModule="CarsTest" customModuleProvider="target">
<rect key="frame" x="0.0" y="22" width="320" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WCw-Qf-5nD" id="37f-cq-3Eg">
<frame key="frameInset" width="375" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Arm-wq-HPj">
<frame key="frameInset" minX="15" width="345" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="vID-JU-sEI">
<rect key="frame" x="5" y="5" width="135" height="69.5"/>
<constraints>
<constraint firstAttribute="width" secondItem="vID-JU-sEI" secondAttribute="height" multiplier="256:132" id="Kcb-As-8bj"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="POk-rF-lfC">
<rect key="frame" x="148" y="5" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="vID-JU-sEI" firstAttribute="top" secondItem="37f-cq-3Eg" secondAttribute="top" constant="5" id="59x-p5-DPq"/>
<constraint firstItem="POk-rF-lfC" firstAttribute="top" secondItem="vID-JU-sEI" secondAttribute="top" id="7cv-bd-ZP9"/>
<constraint firstItem="vID-JU-sEI" firstAttribute="leading" secondItem="37f-cq-3Eg" secondAttribute="leading" constant="5" id="Zcb-rK-2er"/>
<constraint firstAttribute="bottom" secondItem="vID-JU-sEI" secondAttribute="bottom" constant="5" id="dcz-dc-mOx"/>
<constraint firstItem="POk-rF-lfC" firstAttribute="leading" secondItem="vID-JU-sEI" secondAttribute="trailing" constant="8" id="wbW-e0-aDu"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="nameLabel" destination="POk-rF-lfC" id="2dE-7O-Sfh"/>
<outlet property="picImageView" destination="vID-JU-sEI" id="TpH-yu-tsf"/>
<segue destination="vC3-pB-5Vb" kind="showDetail" identifier="showDetail" id="6S0-TO-JiA"/>
</connections>
</tableViewCell>
Expand All @@ -108,6 +129,9 @@
</connections>
</tableView>
<navigationItem key="navigationItem" title="Master" id="Zdf-7t-Un8"/>
<connections>
<outlet property="view" destination="r7i-6Z-zg0" id="bOr-CK-hJU"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Rux-fX-hf1" sceneMemberID="firstResponder"/>
</objects>
Expand All @@ -118,6 +142,7 @@
<objects>
<navigationController id="vC3-pB-5Vb" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand Down
24 changes: 22 additions & 2 deletions CarsTest/Car.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Foundation
import SwiftyJSON

class Car {
var carImageUrl: String?
var color: String?
var fuelLevel: String?
var fuelType: String?
Expand All @@ -29,7 +28,7 @@ class Car {

class func parseJSONDictionary(json: JSON) -> Car {
let car = Car()
car.carImageUrl = json["carImageUrl"].string

car.color = json["color"].string
car.fuelLevel = json["fuelLevel"].string
car.fuelType = json["fuelType"].string
Expand Down Expand Up @@ -58,4 +57,25 @@ class Car {
}
return cars
}

var carImagePath: String? {
guard let color = self.color else {
return nil
}

guard let modelIdentifier = self.modelIdentifier else {
return nil
}

let path = "https://prod.drive-now-content.com/fileadmin/user_upload_global/assets/cars/\(modelIdentifier)/\(color)/2x/car.png"
return path
}

var carImageURL: URL? {
guard let carImagePath = carImagePath else {
return nil
}

return URL(string: carImagePath)
}
}
31 changes: 31 additions & 0 deletions CarsTest/CarTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// CarTableViewCell.swift
// CarsTest
//
// Created by Yurii Kolesnykov on 10.08.17.
// Copyright © 2017 Yurii Kolesnykov. All rights reserved.
//

import UIKit

fileprivate let kReuseID = "CarTableViewCell"
fileprivate let kCellHeight = 80 as CGFloat

class CarTableViewCell: UITableViewCell {

@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var picImageView: UIImageView!

class var reuseID: String {
return kReuseID
}

class var CellHeight: CGFloat {
return kCellHeight
}

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
7 changes: 3 additions & 4 deletions CarsTest/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ class DetailViewController: UIViewController {

@IBOutlet weak var detailDescriptionLabel: UILabel!


func configureView() {
// Update the user interface for the detail item.
if let detail = detailItem {
if let car = car {
if let label = detailDescriptionLabel {
label.text = detail.name
label.text = car.name
}
}
}
Expand All @@ -33,7 +32,7 @@ class DetailViewController: UIViewController {
// Dispose of any resources that can be recreated.
}

var detailItem: Car? {
var car: Car? {
didSet {
// Update the view.
configureView()
Expand Down
Loading

0 comments on commit d1086a9

Please sign in to comment.