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

Notifications You must be signed in to change notification settings

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
classDemoViewController:FLTableComponentController{}
  1. Create a component which inherit of FLTableBaseComponent, and override some methods
classDemoComponent:FLTableBaseComponent{overridefunc cellForRow(at indexPath:IndexPath)->UITableViewCell{letcell:UITableViewCell= super.cellForRow(at: indexPath)return cell }overridefunc numberOfRows()->NSInteger{return2}...}
  1. set dataSource in controller
vararr:Array<FLTableBaseComponent>=[]letcomponent=DemoComponent.init(tableView:self.tableView)letNibComponent=NibDemoComponent.init(tableView:self.tableView) arr.append(component) arr.append(NibComponent)self.components = arr

Custom Use

  1. custom tableView style and rect
overridevartableViewStyle:UITableViewStyle{returnUITableViewStyle.grouped }overridefunc customRect()->CGRect{returnself.view.bounds }
  1. override the method of register() to regist custom cell、header or footer
overridefunc 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
overridefunc 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 }overridefunc 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 }overridefunc heightForHeader(at section:Int)->CGFloat{ // return height for header }overridefunc footerView(at section:Int)->FLTableViewHeaderFooterView?{ // the same as header }overridefunc additionalOperationForReuseFooterView(_ footerView:FLTableViewHeaderFooterView?){ // the same as header }overridefunc heightForFooter(at section:Int)->CGFloat{ // return height for footer }
  1. custom header or footer of tableView
overridefunc headerView(of tableView:UITableView)->UIView?{ // return tableHeaderView }overridefunc footerView(of tableView:UITableView)->UIView?{ // return tableFooterView }

Author

[email protected]简书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