All Projects → maxsokolov → Tablekit

maxsokolov / Tablekit

Licence: mit
Type-safe declarative table views.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Tablekit

Automatic Height Tagcells
This is a sample project to implement features with dynamic height of UITableViewCell based on autolayout, tags aligned automatically and clickable tags.
Stars: ✭ 229 (-59.61%)
Mutual labels:  autolayout, uitableview, uitableviewcell
Uitableviewdynamiclayoutcacheheight
🖖高性能的自动计算采用 Autolayout 布局的 UITableViewCell 和 UITableViewHeaderFooterView 的高度,内部自动管理高度缓存。
Stars: ✭ 360 (-36.51%)
Mutual labels:  autolayout, uitableview, uitableviewcell
Flowkit
A declarative type-safe framework for building fast and flexible list with Tables & Collection
Stars: ✭ 215 (-62.08%)
Mutual labels:  autolayout, uitableview
Genericdatasource
A generic small reusable components for data source implementation for UITableView/UICollectionView in Swift.
Stars: ✭ 127 (-77.6%)
Mutual labels:  generic, uitableview
StackableTableView
A UITableView subclass that enables setting an array of views for both headers and footers utilizing UIStackView
Stars: ✭ 72 (-87.3%)
Mutual labels:  uitableview, autolayout
Tangramkit
TangramKit is a powerful iOS UI framework implemented by Swift. It integrates the functions with Android layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,LayoutSizeClass to build your App 自动布局 UIView UITableView UICollectionView
Stars: ✭ 984 (+73.54%)
Mutual labels:  autolayout, uitableview
Basecomponents
BaseComponents aims to provide easily reusable and understandable components to increase productivity with UIKit and Foundation APIs
Stars: ✭ 92 (-83.77%)
Mutual labels:  autolayout, uitableview
TreeView
"TreeView - sub-cells simplified" (c). Enable subcells in UITableView with a single drop-in extension. CocoaPod:
Stars: ✭ 54 (-90.48%)
Mutual labels:  uitableview, uitableviewcell
Tdbadgedcell
TDBadgedCell is a table view cell class that adds a badge, similar to the badges in Apple's own apps
Stars: ✭ 1,444 (+154.67%)
Mutual labels:  uitableview, uitableviewcell
ios ui recipe showcase
iOSアプリ開発 - UI実装であると嬉しいレシピブック掲載サンプル
Stars: ✭ 54 (-90.48%)
Mutual labels:  uitableview, autolayout
UITableViewCellAnimation
Basic tabeview cell animation for best way to display cell
Stars: ✭ 31 (-94.53%)
Mutual labels:  uitableview, uitableviewcell
TableViewKit
Empowering UITableView with painless multi-type cell support and built-in automatic state transition animations
Stars: ✭ 105 (-81.48%)
Mutual labels:  uitableview, uitableviewcell
Autolayoutexamplewithmasonry
Different Autolayout examples with Masonry. 用Masonry写的Autolayout案例,持续更新中。详细解答请看tutuge.me
Stars: ✭ 694 (+22.4%)
Mutual labels:  autolayout, uitableviewcell
Expandabletable
AZExpandable is a lightweight proxy for UITableView to expand cells.
Stars: ✭ 218 (-61.55%)
Mutual labels:  uitableview, uitableviewcell
Reverseextension
A UITableView extension that enables cell insertion from the bottom of a table view.
Stars: ✭ 1,631 (+187.65%)
Mutual labels:  uitableview, uitableviewcell
AUPickerCell
Embedded picker view for table cells.
Stars: ✭ 19 (-96.65%)
Mutual labels:  uitableview, uitableviewcell
Mdl11 generics
Example project that was demonstrated on MDL #11 meetup - https://www.youtube.com/watch?v=A4FrEyFBjVA. Medium article - https://medium.com/chili-labs/configuring-multiple-cells-with-generics-in-swift-dcd5e209ba16
Stars: ✭ 50 (-91.18%)
Mutual labels:  uitableview, uitableviewcell
Datasource
Simplifies the setup of UITableView data sources using type-safe descriptors for cells and sections. Animated diffing built-in.
Stars: ✭ 72 (-87.3%)
Mutual labels:  uitableview, uitableviewcell
Multiple-collectionView-in-Multiple-tableView-cells
UICollectionView is embed in UITableViewCell. The collection views are horizontal scrollable. The UITableView can have a section title for each UICollectionView and the number of UICollectionView is equal to the number of sections.
Stars: ✭ 23 (-95.94%)
Mutual labels:  uitableview, uitableviewcell
WBChainMenu
This will show horizontal menu to a UITableViewCell with chain animation
Stars: ✭ 28 (-95.06%)
Mutual labels:  uitableview, uitableviewcell

TableKit

Build Status Swift 5.1 compatible Carthage compatible CocoaPods compatible Platform iOS License: MIT

TableKit is a super lightweight yet powerful generic library that allows you to build complex table views in a declarative type-safe manner. It hides a complexity of UITableViewDataSource and UITableViewDelegate methods behind the scene, so your code will be look clean, easy to read and nice to maintain.

Features

  • [x] Type-safe generic cells
  • [x] Functional programming style friendly
  • [x] The easiest way to map your models or view models to cells
  • [x] Automatic cell registration*
  • [x] Correctly handles autolayout cells with multiline labels
  • [x] Chainable cell actions (select/deselect etc.)
  • [x] Support cells created from code, xib, or storyboard
  • [x] Support different cells height calculation strategies
  • [x] Support portrait and landscape orientations
  • [x] No need to subclass
  • [x] Extensibility

Getting Started

An example app is included demonstrating TableKit's functionality.

Basic usage

Create your rows:

import TableKit

let row1 = TableRow<StringTableViewCell>(item: "1")
let row2 = TableRow<IntTableViewCell>(item: 2)
let row3 = TableRow<UserTableViewCell>(item: User(name: "John Doe", rating: 5))

Put rows into section:

let section = TableSection(rows: [row1, row2, row3])

And setup your table:

let tableDirector = TableDirector(tableView: tableView)
tableDirector += section

Done. Your table is ready. Your cells have to conform to ConfigurableCell protocol:

class StringTableViewCell: UITableViewCell, ConfigurableCell {

    func configure(with string: String) {
		
        textLabel?.text = string
    }
}

class UserTableViewCell: UITableViewCell, ConfigurableCell {

    static var estimatedHeight: CGFloat? {
        return 100
    }

    // is not required to be implemented
    // by default reuse id is equal to cell's class name
    static var reuseIdentifier: String {
        return "my id"
    }

    func configure(with user: User) {
		
        textLabel?.text = user.name
        detailTextLabel?.text = "Rating: \(user.rating)"
    }
}

You could have as many rows and sections as you need.

Row actions

It nice to have some actions that related to your cells:

let action = TableRowAction<StringTableViewCell>(.click) { (options) in

    // you could access any useful information that relates to the action

    // options.cell - StringTableViewCell?
    // options.item - String
    // options.indexPath - IndexPath
    // options.userInfo - [AnyHashable: Any]?
}

let row = TableRow<StringTableViewCell>(item: "some", actions: [action])

Or, using nice chaining approach:

let row = TableRow<StringTableViewCell>(item: "some")
    .on(.click) { (options) in
	
    }
    .on(.shouldHighlight) { (options) -> Bool in
        return false
    }

You could find all available actions here.

Custom row actions

You are able to define your own actions:

struct MyActions {
    
    static let ButtonClicked = "ButtonClicked"
}

class MyTableViewCell: UITableViewCell, ConfigurableCell {

    @IBAction func myButtonClicked(sender: UIButton) {
	
        TableCellAction(key: MyActions.ButtonClicked, sender: self).invoke()
    }
}

And handle them accordingly:

let myAction = TableRowAction<MyTableViewCell>(.custom(MyActions.ButtonClicked)) { (options) in

}

Multiple actions with same type

It's also possible to use multiple actions with same type:

let click1 = TableRowAction<StringTableViewCell>(.click) { (options) in }
click1.id = "click1" // optional

let click2 = TableRowAction<StringTableViewCell>(.click) { (options) in }
click2.id = "click2" // optional

let row = TableRow<StringTableViewCell>(item: "some", actions: [click1, click2])

Could be useful in case if you want to separate your logic somehow. Actions will be invoked in order which they were attached.

If you define multiple actions with same type which also return a value, only last return value will be used for table view.

You could also remove any action by id:

row.removeAction(forActionId: "action_id")

Advanced

Cell height calculating strategy

By default TableKit relies on self-sizing cells. In that case you have to provide an estimated height for your cells:

class StringTableViewCell: UITableViewCell, ConfigurableCell {

    // ...

    static var estimatedHeight: CGFloat? {
        return 255
    }
}

It's enough for most cases. But you may be not happy with this. So you could use a prototype cell to calculate cells heights. To enable this feature simply use this property:

let tableDirector = TableDirector(tableView: tableView, shouldUsePrototypeCellHeightCalculation: true)

It does all dirty work with prototypes for you behind the scene, so you don't have to worry about anything except of your cell configuration:

class ImageTableViewCell: UITableViewCell, ConfigurableCell {

    func configure(with url: NSURL) {
		
        loadImageAsync(url: url, imageView: imageView)
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        
        contentView.layoutIfNeeded()
        multilineLabel.preferredMaxLayoutWidth = multilineLabel.bounds.size.width
    }
}

You have to additionally set preferredMaxLayoutWidth for all your multiline labels.

Functional programming

It's never been so easy to deal with table views.

let users = /* some users array */

let click = TableRowAction<UserTableViewCell>(.click) {

}

let rows = users.filter({ $0.state == .active }).map({ TableRow<UserTableViewCell>(item: $0.name, actions: [click]) })

tableDirector += rows

Done, your table is ready.

Automatic cell registration

TableKit can register your cells in a table view automatically. In case if your reusable cell id matches cell's xib name:

MyTableViewCell.swift
MyTableViewCell.xib

You can also turn off this behaviour:

let tableDirector = TableDirector(tableView: tableView, shouldUseAutomaticCellRegistration: false)

and register your cell manually.

Installation

CocoaPods

To integrate TableKit into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'TableKit'

Carthage

Add the line github "maxsokolov/tablekit" to your Cartfile.

Manual

Clone the repo and drag files from Sources folder into your Xcode project.

Requirements

  • iOS 8.0
  • Xcode 9.0

Changelog

Keep an eye on changes.

License

TableKit is available under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].