Commit aae30271 by Javier Heisekce

Expande seccion

parent 88cbd54a
......@@ -12,7 +12,7 @@
CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; };
CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; };
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 */; };
CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; };
/* End PBXBuildFile section */
......@@ -25,7 +25,7 @@
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>"; };
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>"; };
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -68,7 +68,7 @@
CE3351F9241A65D500BA57CA /* Info.plist */,
CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */,
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */,
CEC259D7241FAC79005237F5 /* File.swift */,
CEC259D7241FAC79005237F5 /* ContactStruct.swift */,
);
path = ContactsApp;
sourceTree = "<group>";
......@@ -144,7 +144,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CEC259D8241FAC79005237F5 /* File.swift in Sources */,
CEC259D8241FAC79005237F5 /* ContactStruct.swift in Sources */,
CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */,
CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */,
CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */,
......
//
// File.swift
// ContactStruct.swift
// ContactsApp
//
// Created by User on 3/16/20.
......@@ -7,7 +7,9 @@
//
import Foundation
import ContactsUI
class Contacts {
struct ContactStruct {
var isExpanded: Bool
let contacts : [CNContact]
}
......@@ -12,9 +12,9 @@ import ContactsUI
class ContactsViewController: UIViewController {
@IBOutlet weak var contactsTable: UITableView!
var contactStruct = [ContactStruct]()
var contacts = [CNContact]()
var contactsBackup = [CNContact]()
//var contactsBackup = [CNContact]()
let contactStore = CNContactStore()
override func viewDidLoad() {
......@@ -34,6 +34,8 @@ class ContactsViewController: UIViewController {
// Array containing all unified contacts from everywhere
self.contacts.append(contact)
}
let contactsExpandables = ContactStruct(isExpanded: true, contacts: contacts)
self.contactStruct = [contactsExpandables]
}
catch {
print("unable to fetch contacts")
......@@ -52,12 +54,19 @@ class ContactsViewController: UIViewController {
}
extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
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")!
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
}
......@@ -77,20 +86,30 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15)
button.backgroundColor = .systemGray4
button.addTarget(self, action: #selector(closeSection), for: .touchUpInside)
button.tag = section
return button//ʌΛ
}
@objc func closeSection() {
contactsBackup = contacts
let section = 0
@objc func closeSection(button : UIButton) {
//contactsBackup = contacts
let section = button.tag
var indexPaths = [IndexPath]()
for row in contacts.indices {
for row in contactStruct[section].contacts.indices {
let indexPath = IndexPath(row: row, section: section)
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