value actions
This commit is contained in:
parent
bf01dc638a
commit
708f164c96
Binary file not shown.
|
|
@ -20,13 +20,21 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
public protocol Row {
|
||||
|
||||
public protocol RowConfigurable {
|
||||
|
||||
func configure(cell: UITableViewCell)
|
||||
}
|
||||
|
||||
public protocol RowActionable {
|
||||
|
||||
func invoke(action: TableRowActionType, cell: UITableViewCell?, path: NSIndexPath) -> Any?
|
||||
}
|
||||
|
||||
public protocol Row: RowConfigurable, RowActionable {
|
||||
|
||||
var reusableIdentifier: String { get }
|
||||
var estimatedHeight: CGFloat { get }
|
||||
var defaultHeight: CGFloat { get }
|
||||
|
||||
func configure(cell: UITableViewCell)
|
||||
}
|
||||
|
||||
public class TableRow<ItemType, CellType: ConfigurableCell where CellType.T == ItemType, CellType: UITableViewCell>: Row {
|
||||
|
|
@ -50,14 +58,23 @@ public class TableRow<ItemType, CellType: ConfigurableCell where CellType.T == I
|
|||
self.item = item
|
||||
}
|
||||
|
||||
// MARK: - RowConfigurable -
|
||||
|
||||
public func configure(cell: UITableViewCell) {
|
||||
(cell as? CellType)?.configure(item)
|
||||
}
|
||||
|
||||
// MARK: - RowActionable -
|
||||
|
||||
public func invoke(action: TableRowActionType, cell: UITableViewCell?, path: NSIndexPath) -> Any? {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MARK: - actions -
|
||||
|
||||
public func addAction(action: TableRowAction<ItemType, CellType>) {
|
||||
|
||||
public func action(action: TableRowAction<ItemType, CellType>) -> Self {
|
||||
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
public enum TableActionType {
|
||||
public enum TableRowActionType {
|
||||
|
||||
case Click
|
||||
case Custom(String)
|
||||
|
|
@ -32,10 +32,11 @@ protocol RowAction {
|
|||
|
||||
public class TableRowAction<ItemType, CellType: ConfigurableCell where CellType.T == ItemType, CellType: UITableViewCell>: RowAction {
|
||||
|
||||
public init(_ action: TableActionType, handler: (row: TableRow<ItemType, CellType>) -> Void) {
|
||||
|
||||
|
||||
|
||||
|
||||
public init(_ action: ActionType, handler: (row: TableRow<ItemType, CellType>) -> Void) {
|
||||
|
||||
}
|
||||
|
||||
public init<T>(_ action: ActionType, handler: (row: TableRow<ItemType, CellType>) -> T) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ class MainController: UIViewController {
|
|||
|
||||
|
||||
|
||||
let a = TableRowAction<String, StoryboardImageTableViewCell>(.Click) {
|
||||
let a = TableRowAction<String, StoryboardImageTableViewCell>(.click) {
|
||||
(row) in
|
||||
|
||||
}
|
||||
|
|
@ -41,10 +41,15 @@ class MainController: UIViewController {
|
|||
let row2 = TableRow<String, StoryboardImageTableViewCell>(item: "2")
|
||||
let row3 = TableRow<String, StoryboardImageTableViewCell>(item: "3", actions: [a])
|
||||
|
||||
|
||||
row1
|
||||
.action(TableRowAction(.click) { (row) in
|
||||
|
||||
.addAction(TableRowAction(.Click) { (row) in
|
||||
|
||||
|
||||
})
|
||||
.action(TableRowAction(.click) { (row) -> String in
|
||||
|
||||
return ""
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue