From d484a6da54b094941b17f7b04de106301a1dd77e Mon Sep 17 00:00:00 2001 From: lucasmllr Date: Sat, 7 May 2016 11:34:20 +0200 Subject: [PATCH 1/3] Kann keine tableviewcell auf tableview ziehen --- Lifetime.xcodeproj/project.pbxproj | 4 +++ Lifetime/ContactListViewController.swift | 36 ++++++++++++++++++++++++ Lifetime/Main.storyboard | 14 ++++----- LifetimeCell.swift | 26 +++++++++++++++++ 4 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 LifetimeCell.swift diff --git a/Lifetime.xcodeproj/project.pbxproj b/Lifetime.xcodeproj/project.pbxproj index 31853da..f4d8cfb 100644 --- a/Lifetime.xcodeproj/project.pbxproj +++ b/Lifetime.xcodeproj/project.pbxproj @@ -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 */; }; + E9392BAA1CDBE7C600BA0FDD /* LifetimeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9392BA91CDBE7C600BA0FDD /* LifetimeCell.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -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; }; + E9392BA91CDBE7C600BA0FDD /* LifetimeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LifetimeCell.swift; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,6 +71,7 @@ 870312481CD4EECD00A48B90 /* View */ = { isa = PBXGroup; children = ( + E9392BA91CDBE7C600BA0FDD /* LifetimeCell.swift */, ); name = View; sourceTree = ""; @@ -177,6 +180,7 @@ 8710450A1CD4ED800091710A /* Lifetime.swift in Sources */, 871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */, 871045011CD4ED800091710A /* AppDelegate.swift in Sources */, + E9392BAA1CDBE7C600BA0FDD /* LifetimeCell.swift in Sources */, 871045081CD4ED800091710A /* ContactListViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 7056454..e3074c7 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -97,3 +97,39 @@ extension ContactListViewController: UISearchResultsUpdating { } } + +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 contact.lifetime != nil { + cell.selectionStyle = .Default + cell.accessoryType = .DisclosureIndicator + } else { + cell.selectionStyle = .None + cell.accessoryType = .None + } + return cell + } +} + + + + + + + + + + + diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index f56967f..46b74df 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -34,15 +34,15 @@ - + - diff --git a/LifetimeCell.swift b/LifetimeCell.swift new file mode 100644 index 0000000..dfee44e --- /dev/null +++ b/LifetimeCell.swift @@ -0,0 +1,26 @@ +// +// LifetimeCell.swift +// Lifetime +// +// Created by Lucas Moeller on 05.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 + } + } +} \ No newline at end of file From bb9c13f6e1ebad1cddc48d0ad4ad31612a5cb1b7 Mon Sep 17 00:00:00 2001 From: lucasmllr Date: Sat, 7 May 2016 22:46:14 +0200 Subject: [PATCH 2/3] alles da aber wieder SIGABRT.. --- Lifetime/ContactListViewController.swift | 10 +++++-- Lifetime/Main.storyboard | 37 +++++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index e3074c7..3987814 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -68,8 +68,11 @@ class ContactListViewController: UITableViewController { 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 @@ -121,6 +124,9 @@ extension ContactListViewController { } return cell } + + + } diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index 46b74df..590a349 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -68,7 +68,7 @@ - + @@ -78,6 +78,35 @@ + + + + + + + + + + + + + + + + + @@ -88,7 +117,7 @@ - + From 949397d46f91b66f1a892cb89c0a24515161aa06 Mon Sep 17 00:00:00 2001 From: lucasmllr Date: Mon, 16 May 2016 20:44:32 +0200 Subject: [PATCH 3/3] =?UTF-8?q?jetzt=20compiliert=20es=20und=20=C3=B6ffnet?= =?UTF-8?q?=20die=20contact=20tableview,=20wenn=20ich=20aber=20einen=20kon?= =?UTF-8?q?takt=20anklicke=20kommt=20folgender=20fehler:=20fatal=20error:?= =?UTF-8?q?=20unexpectedly=20found=20nil=20while=20unwrapping=20an=20Optio?= =?UTF-8?q?nal=20value=20..gibst=20du=20noch=20einen=20tipp=20was=20los=20?= =?UTF-8?q?ist=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lifetime/Main.storyboard | 49 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index 590a349..72b9a2a 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -3,7 +3,6 @@ - @@ -29,46 +28,18 @@ - + - - - - - - - - - - - - - - - + - - - - - + @@ -79,21 +50,21 @@ - + - + - - + @@ -117,7 +88,7 @@ - +