diff --git a/Lifetime.xcodeproj/project.pbxproj b/Lifetime.xcodeproj/project.pbxproj index 31853da..b6e9515 100644 --- a/Lifetime.xcodeproj/project.pbxproj +++ b/Lifetime.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3357D6731CDC8C6800523ABB /* LifetimeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3357D6721CDC8C6800523ABB /* LifetimeCell.swift */; }; 870312411CD4EDBC00A48B90 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8703123F1CD4EDBC00A48B90 /* LaunchScreen.storyboard */; }; 870312421CD4EDBC00A48B90 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 870312401CD4EDBC00A48B90 /* Main.storyboard */; }; 871045011CD4ED800091710A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871044F21CD4ED800091710A /* AppDelegate.swift */; }; @@ -17,6 +18,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 3357D6721CDC8C6800523ABB /* LifetimeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LifetimeCell.swift; path = Lifetime/LifetimeCell.swift; sourceTree = SOURCE_ROOT; }; 8703123F1CD4EDBC00A48B90 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = Lifetime/LaunchScreen.storyboard; sourceTree = SOURCE_ROOT; }; 870312401CD4EDBC00A48B90 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Lifetime/Main.storyboard; sourceTree = SOURCE_ROOT; }; 871044D91CD3C9860091710A /* Lifetime.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Lifetime.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -69,6 +71,7 @@ 870312481CD4EECD00A48B90 /* View */ = { isa = PBXGroup; children = ( + 3357D6721CDC8C6800523ABB /* LifetimeCell.swift */, ); name = View; sourceTree = ""; @@ -177,6 +180,7 @@ 8710450A1CD4ED800091710A /* Lifetime.swift in Sources */, 871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */, 871045011CD4ED800091710A /* AppDelegate.swift in Sources */, + 3357D6731CDC8C6800523ABB /* LifetimeCell.swift in Sources */, 871045081CD4ED800091710A /* ContactListViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 7056454..1b6386b 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -75,6 +75,39 @@ class ContactListViewController: UITableViewController { break } } + 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 + } + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + switch segue.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 + } + } + } @@ -95,5 +128,26 @@ extension ContactListViewController: UISearchResultsUpdating { loadContacts(filteredBy: nil) } } - -} + } + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lifetime/LifetimeCell.swift b/Lifetime/LifetimeCell.swift new file mode 100644 index 0000000..dba11b8 --- /dev/null +++ b/Lifetime/LifetimeCell.swift @@ -0,0 +1,26 @@ +// +// LifetimeCell.swift +// Lifetime +// +// Created by Reiser, Philipp Luca on 06.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 + } + } +} diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index f56967f..460979b 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -3,7 +3,6 @@ - @@ -32,39 +31,10 @@ - - - - - - - - - - - - - - - - - - - @@ -78,6 +48,35 @@ + + + + + + + + + + + + + + + + +