Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alicanbatur/abexpandableview
Expandable, collapsible, filterable and single/multi selectable table view.
https://github.com/alicanbatur/abexpandableview
cocoapod cocoapods collapsible expandable filterable ios mvvm pod protocol protocol-oriented-programming reusable searchbar selectable swift swift4 tableview ui ui-components uicomponent
Last synced: 3 months ago
JSON representation
Expandable, collapsible, filterable and single/multi selectable table view.
- Host: GitHub
- URL: https://github.com/alicanbatur/abexpandableview
- Owner: alicanbatur
- License: mit
- Created: 2017-12-14T10:53:29.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-17T09:10:27.000Z (about 5 years ago)
- Last Synced: 2024-10-28T00:54:18.117Z (3 months ago)
- Topics: cocoapod, cocoapods, collapsible, expandable, filterable, ios, mvvm, pod, protocol, protocol-oriented-programming, reusable, searchbar, selectable, swift, swift4, tableview, ui, ui-components, uicomponent
- Language: Swift
- Size: 70.3 KB
- Stars: 135
- Watchers: 4
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ABExpandableView
[![CI Status](http://img.shields.io/travis/alicanbatur/ABExpandableView.svg?style=flat)](https://travis-ci.org/alicanbatur/ABExpandableView)
[![Version](https://img.shields.io/cocoapods/v/ABExpandableView.svg?style=flat)](http://cocoapods.org/pods/ABExpandableView)
[![License](https://img.shields.io/cocoapods/l/ABExpandableView.svg?style=flat)](http://cocoapods.org/pods/ABExpandableView)
[![Platform](https://img.shields.io/cocoapods/p/ABExpandableView.svg?style=flat)](http://cocoapods.org/pods/ABExpandableView)## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first. Then run `ABExpandableView.xcworkspace` which is under `/Example` folder.
## Requirements
- Swift 4
- Xcode 9
## InstallationABExpandableView is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'ABExpandableView'
```
## UsageFirst, import `ABExpandableView` to your project.
You should have 2 kinds of model objects to use this view that one of them should be section and the other one should be row.
Consider, Section and Row classes are your objects.
```swift
class Section: SectionItem {
var identifier: String!
var name: String!
var expanded: Bool = true
var rows: [RowItem] = [RowItem]()
var rawRows: [RowItem] = [RowItem]() {
didSet {
rows = rawRows
}
}
var selectedRows: [RowItem] = [RowItem]()
}class Row: RowItem {
var identifier: String!
var name: String!
}class MockDataProvider {
class func createMockData() -> [SectionItem] {
var array = [SectionItem]()
let izmir = City()
izmir.identifier = "35"
izmir.name = "İzmir"
let bornova = Town(identifier: "1", name: "Bornova")
let urla = Town(identifier: "2", name: "Urla")
let konak = Town(identifier: "3", name: "Konak")
let izmirRawRows = [bornova, urla, konak]
izmir.rawRows = izmirRawRows
array.append(izmir)
let istanbul = City()
istanbul.identifier = "34"
istanbul.name = "İstanbul"
let kadikoy = Town(identifier: "4", name: "Kadıköy")
let maltepe = Town(identifier: "5", name: "Maltepe")
let beykoz = Town(identifier: "6", name: "Beykoz")
let istanbulRawRows = [kadikoy, maltepe, beykoz]
istanbul.rawRows = istanbulRawRows
array.append(istanbul)
return array
}
}
```After you create your models, you should open ABExpandableView with injecting those model array.
```swift
@IBAction func buttonTapped(_ sender: Any) {
let cities = MockDataProvider.createMockData()
let expandableSectionsViewModel = ExpandableSectionsViewModel(cities)
let expandableSectionViewController = ExpandableSectionsViewController.newInstance(expandableSectionsViewModel)
expandableSectionViewController.title = "Choose Town(s)"
expandableSectionViewController.delegate = self
self.navigationController?.pushViewController(expandableSectionViewController, animated: true)
}
```Here, let ABExpandableView handle the rest.
One last thing;
You can get selected items using the delegation;```swift
func didSelectItems(_ items: [RowItem]) {
let names = items.flatMap { $0.name }.joined(separator: ", ")
// "Bornova, Kadıköy"
}
```## Author
alicanbatur, [email protected]
## License
ABExpandableView is available under the MIT license. See the LICENSE file for more info.