Commit aae30271 by Javier Heisekce

Expande seccion

parent 88cbd54a
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; }; CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; };
CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; }; CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; };
CE3351F8241A65D500BA57CA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */; }; CE3351F8241A65D500BA57CA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */; };
CEC259D8241FAC79005237F5 /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC259D7241FAC79005237F5 /* File.swift */; }; CEC259D8241FAC79005237F5 /* ContactStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC259D7241FAC79005237F5 /* ContactStruct.swift */; };
CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */; }; CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */; };
CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; }; CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
CE3351F4241A65D500BA57CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; CE3351F4241A65D500BA57CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
CE3351F7241A65D500BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; CE3351F7241A65D500BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CEC259D7241FAC79005237F5 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; }; CEC259D7241FAC79005237F5 /* ContactStruct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactStruct.swift; sourceTree = "<group>"; };
CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = "<group>"; }; CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = "<group>"; };
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = "<group>"; }; CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
CE3351F9241A65D500BA57CA /* Info.plist */, CE3351F9241A65D500BA57CA /* Info.plist */,
CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */, CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */,
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */, CEC9A380241C096D00F024EE /* SingleContactViewController.swift */,
CEC259D7241FAC79005237F5 /* File.swift */, CEC259D7241FAC79005237F5 /* ContactStruct.swift */,
); );
path = ContactsApp; path = ContactsApp;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
CEC259D8241FAC79005237F5 /* File.swift in Sources */, CEC259D8241FAC79005237F5 /* ContactStruct.swift in Sources */,
CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */, CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */,
CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */, CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */,
CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */, CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */,
......
// //
// File.swift // ContactStruct.swift
// ContactsApp // ContactsApp
// //
// Created by User on 3/16/20. // Created by User on 3/16/20.
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
// //
import Foundation import Foundation
import ContactsUI
class Contacts { struct ContactStruct {
var isExpanded: Bool
let contacts : [CNContact]
} }
...@@ -12,9 +12,9 @@ import ContactsUI ...@@ -12,9 +12,9 @@ import ContactsUI
class ContactsViewController: UIViewController { class ContactsViewController: UIViewController {
@IBOutlet weak var contactsTable: UITableView! @IBOutlet weak var contactsTable: UITableView!
var contactStruct = [ContactStruct]()
var contacts = [CNContact]() var contacts = [CNContact]()
var contactsBackup = [CNContact]() //var contactsBackup = [CNContact]()
let contactStore = CNContactStore() let contactStore = CNContactStore()
override func viewDidLoad() { override func viewDidLoad() {
...@@ -34,6 +34,8 @@ class ContactsViewController: UIViewController { ...@@ -34,6 +34,8 @@ class ContactsViewController: UIViewController {
// Array containing all unified contacts from everywhere // Array containing all unified contacts from everywhere
self.contacts.append(contact) self.contacts.append(contact)
} }
let contactsExpandables = ContactStruct(isExpanded: true, contacts: contacts)
self.contactStruct = [contactsExpandables]
} }
catch { catch {
print("unable to fetch contacts") print("unable to fetch contacts")
...@@ -52,12 +54,19 @@ class ContactsViewController: UIViewController { ...@@ -52,12 +54,19 @@ class ContactsViewController: UIViewController {
} }
extension ContactsViewController: UITableViewDelegate, UITableViewDataSource { extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contacts.count if !contactStruct[section].isExpanded {
return 0
}
return contactStruct[section].contacts.count
} }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "contactName")! let cell = tableView.dequeueReusableCell(withIdentifier: "contactName")!
cell.textLabel?.text = "\(contacts[indexPath.row].givenName) \(contacts[indexPath.row].familyName)" let contactCell = contactStruct[indexPath.section].contacts[indexPath.row]
cell.textLabel?.text = "\(contactCell.givenName) \(contactCell.familyName)"
return cell return cell
} }
...@@ -77,20 +86,30 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -77,20 +86,30 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15) button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15)
button.backgroundColor = .systemGray4 button.backgroundColor = .systemGray4
button.addTarget(self, action: #selector(closeSection), for: .touchUpInside) button.addTarget(self, action: #selector(closeSection), for: .touchUpInside)
button.tag = section
return button//ʌΛ return button//ʌΛ
} }
@objc func closeSection() { @objc func closeSection(button : UIButton) {
contactsBackup = contacts //contactsBackup = contacts
let section = 0 let section = button.tag
var indexPaths = [IndexPath]() var indexPaths = [IndexPath]()
for row in contacts.indices { for row in contactStruct[section].contacts.indices {
let indexPath = IndexPath(row: row, section: section) let indexPath = IndexPath(row: row, section: section)
indexPaths.append(indexPath) indexPaths.append(indexPath)
} }
contacts.removeAll()
contactsTable.reloadData() let isExpanded = contactStruct[section].isExpanded
contactStruct[section].isExpanded = !isExpanded
button.setTitle(isExpanded ? "V" : "Λ", for: .normal)
if isExpanded {
contactsTable.deleteRows(at: indexPaths, with: .top)
} else {
contactsTable.insertRows(at: indexPaths, with: .bottom)
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment