diff --git a/Lifetime.xcodeproj/project.pbxproj b/Lifetime.xcodeproj/project.pbxproj index 31853da..db0f035 100644 --- a/Lifetime.xcodeproj/project.pbxproj +++ b/Lifetime.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 17467B2B1CE1EF44009EBC6B /* LifetimeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17467B2A1CE1EF44009EBC6B /* 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 */ + 17467B2A1CE1EF44009EBC6B /* 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 = ( + 17467B2A1CE1EF44009EBC6B /* LifetimeCell.swift */, ); name = View; sourceTree = ""; @@ -177,6 +180,7 @@ 8710450A1CD4ED800091710A /* Lifetime.swift in Sources */, 871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */, 871045011CD4ED800091710A /* AppDelegate.swift in Sources */, + 17467B2B1CE1EF44009EBC6B /* LifetimeCell.swift in Sources */, 871045081CD4ED800091710A /* ContactListViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 7056454..c9eddf0 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -81,8 +81,39 @@ class ContactListViewController: UITableViewController { // MARK: - Table View Datasource -// TODO: implement UITableViewDatasource protocol +// TODO: implement UITableViewDatasource protocol -done +extension ContactListViewController { + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + return 1 // zeigt kontakte zunächst in einer einzelnen Section an + + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return contacts.count // jeder kontankt soll eine neue zeile bekommen + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + + //View komponente: Frage die TableView nach einer wiederverwendbaren Zelle + let cell = tableView.dequeueReusableCellWithIdentifier("LifetimeCell", forIndexPath: indexPath) as! LifetimeCell + + // MODEL-Komponente: Bestimme den Kontakt für diese → Zeile + + 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 + } +} // MARK: - Search Results Updating diff --git a/Lifetime/LaunchScreen.storyboard b/Lifetime/LaunchScreen.storyboard index 2e721e1..0a546bb 100644 --- a/Lifetime/LaunchScreen.storyboard +++ b/Lifetime/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -15,7 +16,6 @@ - diff --git a/Lifetime/LifetimeCell.swift b/Lifetime/LifetimeCell.swift new file mode 100644 index 0000000..6daec56 --- /dev/null +++ b/Lifetime/LifetimeCell.swift @@ -0,0 +1,27 @@ +// +// LifetimeCell.swift +// Lifetime +// +// Created by Florian M. on 10/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..a061867 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -78,6 +78,35 @@ + + + + + + + + + + + + + + + + + @@ -88,7 +117,7 @@ - +