Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

die nächste Abgabe wird weniger Konfus #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 */; };
AE4FECD51CF5C45A008A3E34 /* LifetimeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE4FECD41CF5C45A008A3E34 /* 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; };
AE4FECD41CF5C45A008A3E34 /* 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 = (
AE4FECD41CF5C45A008A3E34 /* 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 */,
AE4FECD51CF5C45A008A3E34 /* LifetimeCell.swift in Sources */,
871045081CD4ED800091710A /* ContactListViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
47 changes: 44 additions & 3 deletions Lifetime/ContactListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,28 @@ class ContactListViewController: UITableViewController {


// MARK: User Interaction

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
switch identifier {

case "showContactDetail":
guard let indexPath = self.tableView.indexPathForSelectedRow else { return false }
let contact = contacts[indexPath.row]
return contact.lifetime != nil

default:
return true
}
}

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 All @@ -81,7 +98,31 @@ class ContactListViewController: UITableViewController {

// MARK: - Table View Datasource

// TODO: implement UITableViewDatasource protocol
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 let _ = contact.lifetime {
cell.selectionStyle = .Default
cell.accessoryType = .DisclosureIndicator
} else {
cell.selectionStyle = .None
cell.accessoryType = .None
}
return cell
}

}


// MARK: - Search Results Updating
Expand Down
26 changes: 26 additions & 0 deletions Lifetime/LifetimeCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// LifetimeCell.swift
// Lifetime
//
// Created by Nils Fischer on 30.04.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

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
}
}

}
40 changes: 35 additions & 5 deletions Lifetime/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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="15E65" 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"/>
Expand Down Expand Up @@ -33,16 +33,16 @@
<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"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="KK4-Wj-Xu5">
<rect key="frame" x="20" y="79" width="560" height="61"/>
<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">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" 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">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" 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"/>
Expand Down Expand Up @@ -78,6 +78,36 @@
<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 contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="LifetimeCell" textLabel="1bS-b0-b3Z" detailTextLabel="7Si-5A-gAa" style="IBUITableViewCellStyleValue1" id="WCw-Qf-5nD" 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="WCw-Qf-5nD" id="37f-cq-3Eg">
<rect key="frame" x="0.0" y="0.0" width="567" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1bS-b0-b3Z">
<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="7Si-5A-gAa">
<rect key="frame" x="523" 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>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<segue destination="JEX-9P-axG" kind="show" identifier="showContactDetail" id="Jun-m7-8IT"/>
</connections>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="7bK-jq-Zjz" id="Gho-Na-rnu"/>
Expand Down
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 Nils Fischer on 30.04.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

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
}
}

}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
die naechste Abgabe wird etwas weniger konfus.