From b35496bc47d30980ec407a5778e9601229337beb Mon Sep 17 00:00:00 2001 From: xcode Date: Mon, 23 May 2016 13:50:38 +0200 Subject: [PATCH 1/4] added LifetimeCell.swift --- Lifetime/LifetimeCell.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Lifetime/LifetimeCell.swift diff --git a/Lifetime/LifetimeCell.swift b/Lifetime/LifetimeCell.swift new file mode 100644 index 0000000..0c71f68 --- /dev/null +++ b/Lifetime/LifetimeCell.swift @@ -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 + } + } + +} From bf23ab45a50a9576e6d4e72bb3fadb4f8024935d Mon Sep 17 00:00:00 2001 From: xcode Date: Wed, 25 May 2016 13:09:13 +0200 Subject: [PATCH 2/4] Main.storyboard, ContactListViewController.swift geaendert --- Lifetime/ContactListViewController.swift | 47 ++++++++++++++++++++++-- Lifetime/Main.storyboard | 40 +++++++++++++++++--- 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 7056454..f0d2744 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -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 @@ -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 diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index f56967f..a71e899 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -33,16 +33,16 @@ - - + + -