Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func selectedSection(sender: UIButton) {
- let previousSelected = self.selectedSection
- self.selectedSection = sender.tag
- if previousSelected != self.selectedSection {
- // one section opens another gets closed
- // workaround so the animation does not look awful for section headers
- print("Previous: (previousSelected)")
- sectionHeaders[previousSelected].toggleIcon()
- print("Selected: (self.selectedSection)")
- sectionHeaders[self.selectedSection].toggleIcon()
- print("***********")
- var indexPathToInsert = [IndexPath]()
- var indexPathToDelete = [IndexPath]()
- for i in 0..<self.menuItems[self.selectedSection].getSubItems().count {
- indexPathToInsert.append(IndexPath(row: i, section: self.selectedSection))
- }
- for i in 0..<self.menuItems[previousSelected].getSubItems().count {
- indexPathToDelete.append(IndexPath(row: i, section: previousSelected))
- }
- tableView.beginUpdates()
- tableView.deleteRows(at: indexPathToDelete, with: .none)
- tableView.insertRows(at: indexPathToInsert, with: .automatic)
- tableView.endUpdates()
- } else {
- // close the section so the selected section is 0 again
- self.selectedSection = 0
- print("Previous: (previousSelected)")
- sectionHeaders[previousSelected].toggleIcon()
- print("***********")
- tableView.reloadSections([previousSelected], with: .none)
- }
- }
- func toggleIcon() {
- isOpen = !isOpen
- print("(isOpen)")
- if isOpen {
- print("Works")
- self.sectionIcon.image = UIImage(named: "arrow-up")
- } else {
- print("Does not work")
- self.sectionIcon.image = UIImage(named: "arrow-down")
- }
- }
- 'Selected: 1'
- true
- Works
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement