- iOS 9.0
- Xcode 11.2
- Swift 5
ARAccordionTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ARAccordionTableView'
Then, run the following command:
pod install
You can use ARAccordionTableView
in simple three easy steps.
- Add pod in your PodFile.
- Change your
UITableView
class withARAccordionTableView
- Subclass your
UITableViewHeaderFooterView
withARAccordionTableViewHeaderView
- Open one section at any time, to achive this set following property like below.
tableView.allowMultipleSectionsOpen = false
and if you want to open multiple sections set value to true
tableView.allowMultipleSectionsOpen = true
- Set
keepOneSectionOpen
property totrue
to keep one section open all the time
tableView.keepOneSectionOpen = true
- Open specific sections on start like below.
tableView.initialOpenSections = [1,3]
- To check if section is open or close
let isSection = tableView.isSectionOpen(1)
- To toggle section use following function
tableView.toggleSection(1)
- To close all sections
tableView.closeAllSections()
extension ViewController : ARAccordionTableViewDelegate {
func tableView(_ tableView: ARAccordionTableView, canInteractWithHeaderAtSection section: Int) -> Bool {
//Return whether user can interact with header View
return true
}
func tableView(_ tableView: ARAccordionTableView, willOpenSection section: Int, withHeader header: UITableViewHeaderFooterView?) {
// called before section is opening
}
func tableView(_ tableView: ARAccordionTableView, didOpenSection section: Int, withHeader header: UITableViewHeaderFooterView?) {
// called after section opened
}
func tableView(_ tableView: ARAccordionTableView, willCloseSection section: Int, withHeader header: UITableViewHeaderFooterView?) {
// called before section closes
}
func tableView(_ tableView: ARAccordionTableView, didCloseSection section: Int, withHeader header: UITableViewHeaderFooterView?) {
// called after section closed
}
func tableView(_ tableView: ARAccordionTableView, didLogPressedSection section: Int, withHeader header: UITableViewHeaderFooterView?, longPressGestureState state: UIGestureRecognizer.State) {
// called when user long press on a tableView header
}
}
AbdulRehman Warraich, [email protected]
ARAccordionTableView is based on FZAccordionTableView.
ARAccordionTableView is released under the MIT license. See LICENSE for details.