ConfigurableCell improvements
This commit is contained in:
parent
db8a8740ff
commit
08ce2d62e4
|
|
@ -4,7 +4,7 @@
|
|||
<a href="https://travis-ci.org/maxsokolov/tablet"><img src="https://travis-ci.org/maxsokolov/tablet.svg" alt="Build Status" /></a>
|
||||
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/Swift2-compatible-4BC51D.svg?style=flat" alt="Swift 2 compatible" /></a>
|
||||
<img src="https://img.shields.io/badge/platform-iOS-blue.svg?style=flat" alt="Platform iOS" />
|
||||
<a href="https://cocoapods.org/pods/tablet"><img src="https://img.shields.io/badge/pod-0.3.0-blue.svg" alt="CocoaPods compatible" /></a>
|
||||
<a href="https://cocoapods.org/pods/tablet"><img src="https://img.shields.io/badge/pod-0.4.0-blue.svg" alt="CocoaPods compatible" /></a>
|
||||
<a href="https://raw.githubusercontent.com/maxsokolov/tablet/master/LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a>
|
||||
</p>
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ import Tablet
|
|||
|
||||
class MyTableViewCell : UITableViewCell, ConfigurableCell {
|
||||
|
||||
typealias Item = User
|
||||
typealias T = User
|
||||
|
||||
static func reusableIdentifier() -> String {
|
||||
return "reusable_id"
|
||||
|
|
@ -95,7 +95,7 @@ class MyTableViewCell : UITableViewCell, ConfigurableCell {
|
|||
return 255
|
||||
}
|
||||
|
||||
func configureWithItem(item: Item) { // item is user here
|
||||
func configure(item: T) { // item is user here
|
||||
|
||||
textLabel?.text = item.username
|
||||
detailTextLabel?.text = item.isActive ? "Active" : "Inactive"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'Tablet'
|
||||
s.version = '0.3.0'
|
||||
s.version = '0.4.0'
|
||||
|
||||
s.homepage = 'https://github.com/maxsokolov/tablet'
|
||||
s.summary = 'Powerful type-safe tool for UITableView. Swift 2.0 is required.'
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -144,7 +144,7 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
|
|||
/**
|
||||
Responsible for building configurable cells of given type and passing items to them.
|
||||
*/
|
||||
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
|
||||
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.T == I, C: UITableViewCell> : TableRowBuilder<I, C> {
|
||||
|
||||
public override var estimatedRowHeight: Float {
|
||||
return C.estimatedHeight()
|
||||
|
|
@ -162,7 +162,7 @@ public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item ==
|
|||
|
||||
switch actionType {
|
||||
case .configure:
|
||||
(cell as? C)?.configureWithItem(items[itemIndex])
|
||||
(cell as? C)?.configure(items[itemIndex])
|
||||
default: break
|
||||
}
|
||||
return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex, userInfo: userInfo)
|
||||
|
|
|
|||
|
|
@ -102,11 +102,11 @@ public class Action {
|
|||
*/
|
||||
public protocol ConfigurableCell {
|
||||
|
||||
associatedtype Item
|
||||
associatedtype T
|
||||
|
||||
static func reusableIdentifier() -> String
|
||||
static func estimatedHeight() -> Float
|
||||
func configureWithItem(item: Item)
|
||||
func configure(_: T)
|
||||
}
|
||||
|
||||
public extension ConfigurableCell where Self: UITableViewCell {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ struct TestTableViewCellOptions {
|
|||
|
||||
class TestTableViewCell: UITableViewCell, ConfigurableCell {
|
||||
|
||||
typealias Item = TestData
|
||||
typealias T = TestData
|
||||
|
||||
static func reusableIdentifier() -> String {
|
||||
return TestTableViewCellOptions.ReusableIdentifier
|
||||
|
|
@ -57,7 +57,7 @@ class TestTableViewCell: UITableViewCell, ConfigurableCell {
|
|||
return TestTableViewCellOptions.EstimatedHeight
|
||||
}
|
||||
|
||||
func configureWithItem(item: Item) {
|
||||
func configure(item: T) {
|
||||
textLabel?.text = item.title
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue