- Notifications
You must be signed in to change notification settings - Fork0
A data-driven library for building complex table views easily
License
MobileUpLLC/TableAdapter
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A data-driven library for building complex table views. Easy updating table view items with animations using automatic diffing algorithm under the hood. Our goal is to think in terms of data instead of index paths while building tables. High-level yet flexible api allows to setup sectioned lists in a few lines of code and take more control over the table where it’s needed. And reusable views configuring helps to keep code clean and stable in a type-safe manner.
- Animated table updates based on auto diffing
- Liner time diffing algorithm
- Type-safe cell, header/footer setup via protocol implementation
- No more
dequeReusable...
- No need to subclass either cell, table or model
- Cell initialization from xib, storyboard or code
- Simple yet flexible sections constructing
- Easy to extend
Item for cells must adoptHashable
protocol.
Table view cell should conform toConfigurable
protocol in order to receive cell item for setup.
extensionCell:Configurable{publicfunc setup(with item:User){ textLabel?.text= item.name}}
Header/Footer view also should adoptConfigurable
protocol to receive config item provided bySection
.
extensionHeader:Configurable{publicfunc setup(with item:String){ textLabel?.text= item}}
SectionSection<Item, SectionId>
is generic type and developer should provide cell models type (Item
) and section id type (SectionId
). It contains information about items, header/footer config (optionally) and must have uniqueid
.
HeaderFooterConfig
contains all information for section header/footer setup. There are two types of it: for default and custom header/footer view type.
letsection=Section<User,Int>( id:0, items:[...], header:.default(title:"Section Begin"))
letsection=Section<User,Int>( id:0, items:[...], header:.custom(item:"Section Begin", reuseId:"FooterId"))
Node: any type of item can be used for header/footer setup.
CreateTableAdapter<Item, SectionId>
. Item and section id are associated types, like inSection
.
Then update adapter with sections.
classViewController:UIViewController{lettableView=...letusers:[User]=[...]private lazyvaradapter=TableAdapter<User,Int>( tableView: tableView, cellIdentifierProvider:{(indexPath, item)->String?inreturn"Cell"}, cellDidSelectHandler:{(table, indexPath, item)in // Handle cell selection for item at indexPath})overridefunc viewDidLoad(){ super.viewDidLoad()setupTable()letsection=Section<User,Int>( id:0, items: users, header:.custom(item:"Begin", reuseId:"HeaderId"), footer:.custom(item:"End", reuseId:"FooterId"),) adapter.update(with:[section], animated:true)}func setupTable(){ tableView.register(Cell.self, forCellReuseIdentifier:"Cell") tableView.register(Header.self, forHeaderFooterViewReuseIdentifier identifier:"HeaderId") tableView.register(Footer.self, forHeaderFooterViewReuseIdentifier identifier:"FooterId")}}
Note: this adapter type sets table view delegate to itself. To handle other table view delegate methods, you must inheritTableAdapter
and implement them.
You can also obtain current adapter sections unisngcurrentSections: [Section]
variable.
Sometimes you need to set delegate for cell, header or footer. For that purpose table adapter hassender
property, which will be passed to configurable view, that adoptsSenderConfigurable
protocol.
extensionCell:SenderConfigurable{func setup(with item:Item, sender:ViewController){ textLabel?.text= object.name delegate= sender}}
To use only one cell type, create adapterwithoutCellReuserIdentifierProvider
lazyvaradapter=TableAdapter<User,Int>(tableView: tableView)
and register cell via storyboard or code for default cell reuse identifier, which is "Cell" under the hood
tableView.register(Cell.self, forCellReuseIdentifier: adapter.defaultCellIdentifier)
- Swift 4.2+
- iOS 9.0+
Add the following toPodfile
:
pod'TableAdapter'
Add the following toCartfile
:
github"MobileUpLLC/TableAdapter"
Download and drag files from Source folder into your Xcode project.
TableAdapter is distributed under theMIT License.
About
A data-driven library for building complex table views easily