From 7db896641439c4cc1e7ef2c9d67dd1987f1e87f9 Mon Sep 17 00:00:00 2001 From: bippo646 Date: Fri, 6 May 2016 15:03:16 +0200 Subject: [PATCH 1/2] Problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die Kontakte können nicht angezeigt werden. --- Lifetime.xcodeproj/project.pbxproj | 4 ++ Lifetime/ContactListViewController.swift | 21 +++++++++- Lifetime/LifetimeCell.swift | 26 ++++++++++++ Lifetime/Main.storyboard | 51 +++++++++++------------- 4 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 Lifetime/LifetimeCell.swift 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..10aaabb 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -95,5 +95,24 @@ extension ContactListViewController: UISearchResultsUpdating { loadContacts(filteredBy: nil) } } + 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 } +} \ No newline at end of file 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..36ec391 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -3,7 +3,6 @@ - @@ -33,38 +32,34 @@ - - - - - - - + + + + + + + + + + + - - - - - - - - - - From 712f428ccc3087c2226e51ef121b461abb568f4c Mon Sep 17 00:00:00 2001 From: bippo646 Date: Sat, 7 May 2016 16:29:25 +0200 Subject: [PATCH 2/2] Problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die prepareForSegue func gibt einen Fehler zurück. --- Lifetime/ContactListViewController.swift | 75 +++++++++++++++++------- Lifetime/Main.storyboard | 50 ++++++++-------- 2 files changed, 82 insertions(+), 43 deletions(-) diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 10aaabb..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,24 +128,26 @@ extension ContactListViewController: UISearchResultsUpdating { loadContacts(filteredBy: nil) } } - 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 } -} \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index 36ec391..460979b 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -31,11 +31,29 @@ - - - + + + + + + + + + + + + + + + + + + + + + - + + + + - - - - - - - - - - - - - - - - - - +