Skip to content

A component for tableView and collectionView, which can greatly reduce your controller codes, also, you can set header or footer more easily 一个tableView和collectionView的组件化实现,解耦瘦身控制器,复杂界面的代码编写更加清晰,方便维护

License

gitkong/FLTableViewComponent

Repository files navigation

FLTableComponent for tableView and collectionView

中文说明

Introduce

A component for tableView and collectionView, which can greatly reduce your controller codes, also, you can set header or footer more easily

Process

what can it do

component

Requirements

swift3+ and xcode8+,新增Objective-C缩减版本(只针对UITableView)

Installation

pod "FLTableComponent"

How To Use (Just give an example for tableView)

  1. 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 {
  
}
  1. 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
  }

  ...

}
  1. 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 Use

  1. custom tableView style and rect
override var tableViewStyle: UITableViewStyle {
  return UITableViewStyle.grouped
}

override func customRect() -> CGRect {
  return self.view.bounds
}
  1. 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
}
  1. 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
}
  1. custom header or footer of tableView
override func headerView(of tableView: UITableView) -> UIView? {
  // return tableHeaderView
}
    
override func footerView(of tableView: UITableView) -> UIView? {
  // return tableFooterView
}

Author

279761135@qq.com简书My blog

Thanks

rickytan RTComponentTableView(Objective-C)

License

FLTableComponent is available under the MIT license. See the LICENSE file for more info.

About

A component for tableView and collectionView, which can greatly reduce your controller codes, also, you can set header or footer more easily 一个tableView和collectionView的组件化实现,解耦瘦身控制器,复杂界面的代码编写更加清晰,方便维护

Resources

License

Stars

Watchers

Forks

Packages

No packages published