From 4c4ec64588ea7229bcb2d8e320e825f32ad08077 Mon Sep 17 00:00:00 2001 From: Javier Heisekce Date: Fri, 27 Mar 2020 09:49:02 -0400 Subject: [PATCH] Mostramos nĂºmeros correctamente --- ContactsApp/Base.lproj/Main.storyboard | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ ContactsApp/ContactsViewController.swift | 5 +---- ContactsApp/SingleContactViewController.swift | 36 ++++++++++++++++++++++++++---------- 3 files changed, 95 insertions(+), 32 deletions(-) diff --git a/ContactsApp/Base.lproj/Main.storyboard b/ContactsApp/Base.lproj/Main.storyboard index 07a73d2..117828e 100644 --- a/ContactsApp/Base.lproj/Main.storyboard +++ b/ContactsApp/Base.lproj/Main.storyboard @@ -62,40 +62,90 @@ - + - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + + + - + + + + diff --git a/ContactsApp/ContactsViewController.swift b/ContactsApp/ContactsViewController.swift index 7f34c2a..e625e06 100644 --- a/ContactsApp/ContactsViewController.swift +++ b/ContactsApp/ContactsViewController.swift @@ -25,7 +25,7 @@ class ContactsViewController: UIViewController { func importContacts() { - let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactImageDataAvailableKey] as [Any] + let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactImageDataKey] as [Any] let request = CNContactFetchRequest( keysToFetch: keys as! [CNKeyDescriptor]) request.sortOrder = CNContactSortOrder.givenName do { @@ -52,9 +52,6 @@ class ContactsViewController: UIViewController { } } self.contactStructArray.append(ContactStruct(isExpanded: true, contacts: contacts, letter: auxLetter)) //agregamos el ultimo nombre - print("CONTACTOS ORDENADOS") - print(self.contactStructArray) - print("======================") } catch { print("unable to fetch contacts") diff --git a/ContactsApp/SingleContactViewController.swift b/ContactsApp/SingleContactViewController.swift index 3a71d15..d916298 100644 --- a/ContactsApp/SingleContactViewController.swift +++ b/ContactsApp/SingleContactViewController.swift @@ -14,24 +14,40 @@ class SingleContactViewController: UIViewController { @IBOutlet weak var contactFullname: UILabel! var selectedContact : CNContact? @IBOutlet weak var profilePic: UIImageView! - @IBOutlet weak var phoneNumber: UILabel! + @IBOutlet weak var phoneNumber: UIButton! + @IBOutlet weak var otherPhoneNumber: UIButton! + @IBOutlet weak var otherPhoneLabel: UILabel! + @IBOutlet weak var phoneLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() if let contact = selectedContact{ title = "\(contact.givenName) \(contact.familyName)" contactFullname.text = "\(contact.givenName) \(contact.familyName)" - //phoneNumber.text = CNLabeledValue.localizedStringForLabel(contact.phoneNumbers) - - if contact.imageDataAvailable { - if let image = contact.imageData { - if let imageData = UIImage(data: image){ - profilePic.image = imageData - } + if let phones = contact.phoneNumbers.first { + let phoneTitle :String = CNLabeledValue.localizedString(forLabel: phones.label! ) + phoneLabel.text = phoneTitle + phoneNumber.setTitle(phones.value.stringValue, for: .normal) + phoneLabel.isHidden = false + phoneNumber.isHidden = false + } + if contact.phoneNumbers.last != contact.phoneNumbers.first, let phones = contact.phoneNumbers.last { + let phoneTitle :String = CNLabeledValue.localizedString(forLabel: phones.label! ) + otherPhoneLabel.text = phoneTitle + otherPhoneNumber.setTitle(phones.value.stringValue, for: .normal) + otherPhoneLabel.isHidden = false + otherPhoneNumber.isHidden = false + } + if let image = contact.imageData { + profilePic.layer.cornerRadius = profilePic.frame.height / 2 + if let imageData = UIImage(data: image){ + profilePic.image = imageData } } - } } - + + @IBAction func callButton(_ sender: Any) { + } + } -- libgit2 0.26.0