Go to file
Max Sokolov 6ee01134ff estimatedRowHeight 2015-11-14 17:49:30 +03:00
Tablet estimatedRowHeight 2015-11-14 17:49:30 +03:00
TabletDemo estimatedRowHeight 2015-11-14 17:49:30 +03:00
LICENSE added podspec and license 2015-11-08 23:47:15 +03:00
README.md bump readme 2015-11-09 00:29:57 +03:00
Tablet.podspec added podspec and license 2015-11-08 23:47:15 +03:00

README.md

Tablet

Tablet is a super lightweight yet powerful generic library that handles a complexity of UITableView's datasource and delegate in a Swift environment. Tablet's goal is to provide an easiest way to create complex table views. With Tablet you don't have to write a messy code of switch or if statement when you deal with bunch of different cells in different sections.

Requirements

  • iOS 8.0+
  • Xcode 7.0+

Installation

CocoaPods

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

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Tablet'

Then, run the following command:

$ pod install

Usage

Very basic

import Tablet

let rowBuilder = TableRowBuilder<User, UITableViewCell>(items: [user1, user2, user3], id: "reusable_id")
	.action(.configure) { data in

		data.cell.textLabel?.text = data.item.title
		data.cell.detailTextLabel?.text = data.item.isActive ? "Active" : "Inactive"
	}

let sectionBuilder = TableSectionBuilder(headerTitle: "Users", rowBuilders: [rowBuilder])

let director = TableDirector(tableView: tableView)
director.appendSections(sectionBuilder)

Cell actions

Tablet provides a chaining approach to handle actions from your cells:

import Tablet

let rowBuilder = TableRowBuilder<User, UITableViewCell>(items: [user1, user2, user3], id: "reusable_id")
	.action(.configure) { data in

	}
	.action(.click) { data in
		
	}
	.action(.willDisplay) { data in
		
	}

Configurable cells

Let's say you want to put your cell configuration logic into cell itself. Say you want to pass your view model (or even model) to your cell. To provide this behaviour simply follow:

import Tablet

class UserTableViewCell : UITableViewCell, ConfigurableCell {

    typealias Item = User
    
    static func reusableIdentifier() -> String {
        return "reusable_id"
    }

    func configureWithItem(item: Item) { // item is user here

    	textLabel?.text = item.title
		detailTextLabel?.text = item.isActive ? "Active" : "Inactive"
    }
}

Once you follow the protocol, simply use TableConfigurableRowBuilder to build cells:

import Tablet

let rowBuilder = TableConfigurableRowBuilder<User, UserTableViewCell>()
rowBuilder.appendItems(users)

tableDirector.appendSection(TableSectionBuilder(rowBuilders: [rowBuilder]))

Custom cell actions

import Tablet

class UserTableViewCell : UITableViewCell {

	@IBAction func buttonClicked(sender: UIButton) {

		Action(key: "action_key", sender: self, userInfo: nil).trigger()
	}
}

And receive this actions with your row builder:

import Tablet

let rowBuilder = TableRowBuilder<User, UserTableViewCell>(items: users, id: "reusable_id")
	.action(.click) { data in
		
	}
	.action(.willDisplay) { data in
		
	}
	.action("action_key") { data in
		
	}

License

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