Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A data-driven library for building complex table views easily

License

NotificationsYou must be signed in to change notification settings

MobileUpLLC/TableAdapter

Repository files navigation

Swift5Platform iOSCocoaPods compatibleCarthage compatibleLicense: MIT

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.

Features

  • Animated table updates based on auto diffing
  • Liner time diffing algorithm
  • Type-safe cell, header/footer setup via protocol implementation
  • No moredequeReusable...
  • No need to subclass either cell, table or model
  • Cell initialization from xib, storyboard or code
  • Simple yet flexible sections constructing
  • Easy to extend

Usage

1. Setup models and reusable views

1.1 Model setup

Item for cells must adoptHashable protocol.

1.2 Cells setup

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}}

1.3 Header/Footer view setup

Header/Footer view also should adoptConfigurable protocol to receive config item provided bySection.

extensionHeader:Configurable{publicfunc setup(with item:String){        textLabel?.text= item}}

2. Create sections

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.

2.1 Default title for header/footer

letsection=Section<User,Int>(    id:0,    items:[...],    header:.default(title:"Section Begin"))

2.2 Custom header/footer view

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.

3. Create adapter and fill it with section

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.

Sender

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}}

One cell type

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)

Requirements

  • Swift 4.2+
  • iOS 9.0+

Installation

CocoaPods

Add the following toPodfile:

pod'TableAdapter'

Carthage

Add the following toCartfile:

github"MobileUpLLC/TableAdapter"

Manual

Download and drag files from Source folder into your Xcode project.

License

TableAdapter is distributed under theMIT License.

About

A data-driven library for building complex table views easily

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp