To run the example project, clone the repo, and run pod install
from the Example directory first.
DPTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'DPTableView', :git => 'https://github.com/ximximik/DPTableView.git', :tag => '0.1.2'
Firstly, needed specify type of Table View in outlet and xib/storyboard
@IBOutlet private weak var tableView: DPTableView!
- Impelement in your cell DPTableViewElementCellProtocol:
public class MyElementCell: UITableViewCell, DPTableViewElementCellProtocol {
public static let estimatedHeight: CGFloat = 100
public func set(viewModel: MyElementCellViewModel) {
...
}
}
- Declare somewhere observable of array of cells viewModel's:
var elementsObservable: Observable<[MyElementCellViewModel]>
- Bind it!
tableView.setup(cellType: MyElementCell.self, viewModels: elementsObservable)
It's work if cells prototype designed in storyboard inside table view. Reuse identifier should equal cell class name. For cells prototype designed in xib file, use function parameter isLoadFromNib
tableView.setup(cellType: MyElementCell.self, viewModels: elementsObservable, isLoadFromNib: true)
TODO
At this moment is possibly set only simple string text
tableView.noItemsText = "Data not yet loaded"
For perform additional setups for cell (delegate setup and etc.), use additional parameter customCellSetup
:
tableView.setup(cellType: MyElementCell.self, viewModels: elementsObservable, isLoadFromNib: true) { [weak self] cell, index in
cell.delegate = self
}
ximximik, [email protected]
DPTableView is available under the MIT license. See the LICENSE file for more info.