Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lifetime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871044FD1CD4ED800091710A /* ContactDetailViewController.swift */; };
871045081CD4ED800091710A /* ContactListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871044FE1CD4ED800091710A /* ContactListViewController.swift */; };
8710450A1CD4ED800091710A /* Lifetime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871045001CD4ED800091710A /* Lifetime.swift */; };
E9392BAA1CDBE7C600BA0FDD /* LifetimeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9392BA91CDBE7C600BA0FDD /* LifetimeCell.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,6 +27,7 @@
871044FE1CD4ED800091710A /* ContactListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactListViewController.swift; path = Lifetime/ContactListViewController.swift; sourceTree = SOURCE_ROOT; };
871044FF1CD4ED800091710A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Lifetime/Info.plist; sourceTree = SOURCE_ROOT; };
871045001CD4ED800091710A /* Lifetime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Lifetime.swift; path = Lifetime/Lifetime.swift; sourceTree = SOURCE_ROOT; };
E9392BA91CDBE7C600BA0FDD /* LifetimeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LifetimeCell.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -69,6 +71,7 @@
870312481CD4EECD00A48B90 /* View */ = {
isa = PBXGroup;
children = (
E9392BA91CDBE7C600BA0FDD /* LifetimeCell.swift */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -177,6 +180,7 @@
8710450A1CD4ED800091710A /* Lifetime.swift in Sources */,
871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */,
871045011CD4ED800091710A /* AppDelegate.swift in Sources */,
E9392BAA1CDBE7C600BA0FDD /* LifetimeCell.swift in Sources */,
871045081CD4ED800091710A /* ContactListViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
46 changes: 44 additions & 2 deletions Lifetime/ContactListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ class ContactListViewController: UITableViewController {

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch segue.identifier! {

// TODO: prepare segue.destinationViewController for each identifier
case "showContactDetail":
guard let indexPath = self.tableView.indexPathForSelectedRow else { break }
let contact = contacts[indexPath.row]
let contactDetailViewController = segue.destinationViewController as! ContactDetailViewController
contactDetailViewController.contact = contact

default:
break
Expand Down Expand Up @@ -97,3 +100,42 @@ extension ContactListViewController: UISearchResultsUpdating {
}

}

extension ContactListViewController {

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int{
return contacts.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("LifetimeCell", forIndexPath: indexPath) as! LifetimeCell
let contact = contacts[indexPath.row]
cell.configureForContact(contact)
if contact.lifetime != nil {
cell.selectionStyle = .Default
cell.accessoryType = .DisclosureIndicator
} else {
cell.selectionStyle = .None
cell.accessoryType = .None
}
return cell
}



}











68 changes: 34 additions & 34 deletions Lifetime/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="RMx-3f-FxP">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="RMx-3f-FxP">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand All @@ -29,46 +28,18 @@
<viewControllerLayoutGuide type="top" id="SYR-Wa-9uf"/>
<viewControllerLayoutGuide type="bottom" id="GAO-Cl-Wes"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="svH-Pt-448">
<view key="view" contentMode="scaleToFill" id="svH-Pt-448" customClass="LifetimeCell" customModule="Lifetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" misplaced="YES" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="KK4-Wj-Xu5">
<rect key="frame" x="20" y="79" width="560" height="60"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uhI-5r-oSa">
<rect key="frame" x="0.0" y="0.0" width="560" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Lifetime" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pm4-Q2-Ezn">
<rect key="frame" x="0.0" y="28" width="560" height="33"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="KK4-Wj-Xu5" firstAttribute="top" secondItem="SYR-Wa-9uf" secondAttribute="bottom" constant="15" id="2Gv-3q-HVN"/>
<constraint firstAttribute="trailingMargin" secondItem="KK4-Wj-Xu5" secondAttribute="trailing" id="N3t-uY-Om8"/>
<constraint firstItem="KK4-Wj-Xu5" firstAttribute="leading" secondItem="svH-Pt-448" secondAttribute="leadingMargin" id="pf6-OM-FJX"/>
<constraint firstItem="GAO-Cl-Wes" firstAttribute="top" relation="greaterThanOrEqual" secondItem="KK4-Wj-Xu5" secondAttribute="bottom" id="wxm-qk-72k"/>
</constraints>
<accessibility key="accessibilityConfiguration" identifier="LifetimeCell"/>
</view>
<toolbarItems/>
<navigationItem key="navigationItem" title="Contact Detail" id="mOI-FS-AaM"/>
<connections>
<outlet property="lifetimeLabel" destination="pm4-Q2-Ezn" id="EvT-zo-cQu"/>
<outlet property="lifetimeTitleLabel" destination="uhI-5r-oSa" id="eNr-Zy-7Rg"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1427" y="-630"/>
<point key="canvasLocation" x="1487" y="-630"/>
</scene>
<!--Contacts-->
<scene sceneID="smW-Zh-WAh">
Expand All @@ -78,6 +49,35 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="LifetimeCell" textLabel="SmL-kd-Rzz" detailTextLabel="RhU-uM-eFI" style="IBUITableViewCellStyleValue1" id="oUX-pa-8G1" customClass="LifetimeCell" customModule="Lifetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="86" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="oUX-pa-8G1" id="6fG-a5-F0R">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="SmL-kd-Rzz">
<rect key="frame" x="15" y="12" width="32" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="RhU-uM-eFI">
<rect key="frame" x="543" y="12" width="42" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="JEX-9P-axG" kind="show" identifier="showContactDetail" id="yNW-Kl-P7M"/>
</connections>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="7bK-jq-Zjz" id="Gho-Na-rnu"/>
Expand All @@ -88,7 +88,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Rux-fX-hf1" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="709" y="-630"/>
<point key="canvasLocation" x="673" y="-630"/>
</scene>
</scenes>
</document>
26 changes: 26 additions & 0 deletions LifetimeCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// LifetimeCell.swift
// Lifetime
//
// Created by Lucas Moeller on 05.05.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import UIKit
import Contacts

class LifetimeCell: UITableViewCell {

func configureForContact (contact: CNContact) {
textLabel?.text = CNContactFormatter.stringFromContact(contact, style: .FullName)
if let lifetime = contact.lifetime {
let lifetimeFormatter = NSDateComponentsFormatter()
lifetimeFormatter.allowedUnits = .Day
lifetimeFormatter.unitsStyle = .Full
detailTextLabel?.text = lifetimeFormatter.stringFromTimeInterval(lifetime)
} else {
detailTextLabel?.text = nil
}
}
}