From 676ec2f72619ba30577bbc7c33eb2bac162a8678 Mon Sep 17 00:00:00 2001 From: Thomas Steinle Date: Mon, 23 May 2016 16:16:25 +0200 Subject: [PATCH] lifetime finished --- Lifetime.xcodeproj/project.pbxproj | 4 ++ Lifetime/ContactListViewController.swift | 50 ++++++++++++++++++++++-- Lifetime/LaunchScreen.storyboard | 6 +-- Lifetime/Main.storyboard | 37 ++++++++++++++++-- LifetimeCell.swift | 28 +++++++++++++ 5 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 LifetimeCell.swift diff --git a/Lifetime.xcodeproj/project.pbxproj b/Lifetime.xcodeproj/project.pbxproj index 31853da..61fc6cf 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 */; }; + E9D6ADD31CF334C900BF4D71 /* LifetimeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9D6ADD21CF334C900BF4D71 /* 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; }; + E9D6ADD21CF334C900BF4D71 /* 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 = ( + E9D6ADD21CF334C900BF4D71 /* LifetimeCell.swift */, ); name = View; sourceTree = ""; @@ -177,6 +180,7 @@ 8710450A1CD4ED800091710A /* Lifetime.swift in Sources */, 871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */, 871045011CD4ED800091710A /* AppDelegate.swift in Sources */, + E9D6ADD31CF334C900BF4D71 /* LifetimeCell.swift in Sources */, 871045081CD4ED800091710A /* ContactListViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 7056454..ca6acaa 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -69,19 +69,37 @@ 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 } } + override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { + + switch identifier { + + case "showContactDetail": + guard let indexPath = self.tableView.indexPathForSelectedRow else {break} + let contact = contacts[indexPath.row] + return contact.lifetime != nil + + default: + break + } + return true + } + + } -// MARK: - Table View Datasource -// TODO: implement UITableViewDatasource protocol // MARK: - Search Results Updating @@ -97,3 +115,29 @@ extension ContactListViewController: UISearchResultsUpdating { } } + +// MARK: - Table View Datasource + +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 + } +} \ No newline at end of file diff --git a/Lifetime/LaunchScreen.storyboard b/Lifetime/LaunchScreen.storyboard index 2e721e1..323bd43 100644 --- a/Lifetime/LaunchScreen.storyboard +++ b/Lifetime/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -15,7 +16,6 @@ - diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index f56967f..5cacf9e 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -33,16 +33,16 @@ - - + + -