A component for tableView and collectionView, which can greatly reduce your controller codes, also, you can set header or footer more easily
swift3+ and xcode8+,新增Objective-C缩减版本(只针对UITableView)
pod "FLTableComponent"
- Create a controller which inherit the class of FLTableComponentController Or Create FLTableViewHandler to handle it, you can check the implementation of FLTableComponentController,and it will show you how to use it
class DemoViewController: FLTableComponentController {
}
- Create a component which inherit of FLTableBaseComponent, and override some methods
class DemoComponent: FLTableBaseComponent {
override func cellForRow(at indexPath: IndexPath) -> UITableViewCell {
let cell : UITableViewCell = super.cellForRow(at: indexPath)
return cell
}
override func numberOfRows() -> NSInteger {
return 2
}
...
}
- set dataSource in controller
var arr : Array<FLTableBaseComponent> = []
let component = DemoComponent.init(tableView: self.tableView)
let NibComponent = NibDemoComponent.init(tableView: self.tableView)
arr.append(component)
arr.append(NibComponent)
self.components = arr
- custom tableView style and rect
override var tableViewStyle: UITableViewStyle {
return UITableViewStyle.grouped
}
override func customRect() -> CGRect {
return self.view.bounds
}
- override the method of register() to regist custom cell、header or footer
override func register() {
// if you need default register, call super
//super.register()
// regist your custom cell、header or footer
}
- create custom header or footer for cell
override func headerView(at section: Int) -> FLTableViewHeaderFooterView? {
// you should call super to get headerView if you just regist the class of FLTableViewHeaderFooterView;
// if you override the method of register() to regist the subclass of FLTableViewHeaderFooterView, you can not call super to get headerView,
// and you should call init(reuseIdentifier: String?, section: Int) and addClickDelegete(for headerFooterView : FLTableViewHeaderFooterView?)
// if this headerView have to accurate tapping event
}
override func additionalOperationForReuseHeaderView(_ headerView: FLTableViewHeaderFooterView?) {
// do some additional operations, at usual, you add label or button or something else into header view to resue
// but if you had registed the class of FLTableViewHeaderFooterView for footerView, this method will be invalid.
//so if you want it to be valiable, do not call super when you override register() method
}
override func heightForHeader(at section: Int) -> CGFloat {
// return height for header
}
override func footerView(at section: Int) -> FLTableViewHeaderFooterView? {
// the same as header
}
override func additionalOperationForReuseFooterView(_ footerView: FLTableViewHeaderFooterView?) {
// the same as header
}
override func heightForFooter(at section: Int) -> CGFloat {
// return height for footer
}
- custom header or footer of tableView
override func headerView(of tableView: UITableView) -> UIView? {
// return tableHeaderView
}
override func footerView(of tableView: UITableView) -> UIView? {
// return tableFooterView
}
rickytan RTComponentTableView(Objective-C)
FLTableComponent is available under the MIT license. See the LICENSE file for more info.