|
|
||
|---|---|---|
| Tablet | ||
| TabletDemo | ||
| README.md | ||
README.md
tablet
Tablet is a super lightweight yet powerful library that handles a complexity of UITableView's datasource and delegate.
Requirements
- iOS 8.0+
- Xcode 7.0+
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)
Additional cell actions
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>()
tableDirector.appendSection(TableSectionBuilder(rowBuilders: [rowBuilder]))