add row action
This commit is contained in:
parent
01dc5dfd21
commit
bf01dc638a
|
|
@ -30,8 +30,9 @@ public protocol Row {
|
|||
}
|
||||
|
||||
public class TableRow<ItemType, CellType: ConfigurableCell where CellType.T == ItemType, CellType: UITableViewCell>: Row {
|
||||
|
||||
|
||||
public let item: ItemType
|
||||
private var actions = [RowAction]()
|
||||
|
||||
public var reusableIdentifier: String {
|
||||
return CellType.reusableIdentifier()
|
||||
|
|
@ -45,11 +46,18 @@ public class TableRow<ItemType, CellType: ConfigurableCell where CellType.T == I
|
|||
return CellType.defaultHeight() ?? UITableViewAutomaticDimension
|
||||
}
|
||||
|
||||
public init(item: ItemType) {
|
||||
public init(item: ItemType, actions: [TableRowAction<ItemType, CellType>]? = nil) {
|
||||
self.item = item
|
||||
}
|
||||
|
||||
public func configure(cell: UITableViewCell) {
|
||||
(cell as? CellType)?.configure(item)
|
||||
}
|
||||
|
||||
// MARK: - actions -
|
||||
|
||||
public func addAction(action: TableRowAction<ItemType, CellType>) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// Copyright (c) 2015 Max Sokolov https://twitter.com/max_sokolov
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
public enum TableActionType {
|
||||
|
||||
case Click
|
||||
case Custom(String)
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -24,21 +24,6 @@ struct TabletNotifications {
|
|||
static let CellAction = "TabletNotificationsCellAction"
|
||||
}
|
||||
|
||||
public enum TableActionType {
|
||||
|
||||
case Click
|
||||
case Custom(String)
|
||||
}
|
||||
|
||||
public class TableRowAction<DataType, CellType> {
|
||||
|
||||
let type: TableActionType
|
||||
|
||||
public init(type: TableActionType, handler: (data: ActionData<DataType, CellType>) -> Void) {
|
||||
self.type = type
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The actions that Tablet provides.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
DA539C9F1CFB025C00368ACB /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA539C9E1CFB025C00368ACB /* Operators.swift */; };
|
||||
DA539CC61D01D44500368ACB /* TableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA539CC51D01D44500368ACB /* TableRow.swift */; };
|
||||
DA9EA7351D06155E0021F650 /* HeightStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA7341D06155E0021F650 /* HeightStrategy.swift */; };
|
||||
DA9EA73E1D08D6AA0021F650 /* TableRowAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA73D1D08D6AA0021F650 /* TableRowAction.swift */; };
|
||||
DAC2D6741C9D743D009E9C19 /* Tablet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAC2D6691C9D743D009E9C19 /* Tablet.framework */; };
|
||||
DAC2D6871C9D7517009E9C19 /* Tablet.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC2D6851C9D7517009E9C19 /* Tablet.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
DAC2D6901C9D799E009E9C19 /* TableDirector.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC2D68C1C9D799E009E9C19 /* TableDirector.swift */; };
|
||||
|
|
@ -35,6 +36,7 @@
|
|||
DA539C9E1CFB025C00368ACB /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
|
||||
DA539CC51D01D44500368ACB /* TableRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRow.swift; sourceTree = "<group>"; };
|
||||
DA9EA7341D06155E0021F650 /* HeightStrategy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeightStrategy.swift; sourceTree = "<group>"; };
|
||||
DA9EA73D1D08D6AA0021F650 /* TableRowAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRowAction.swift; sourceTree = "<group>"; };
|
||||
DAC2D6691C9D743D009E9C19 /* Tablet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Tablet.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
DAC2D6731C9D743D009E9C19 /* TabletTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TabletTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
DAC2D6841C9D7517009E9C19 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
|
@ -99,6 +101,7 @@
|
|||
children = (
|
||||
DAC2D68C1C9D799E009E9C19 /* TableDirector.swift */,
|
||||
DA539CC51D01D44500368ACB /* TableRow.swift */,
|
||||
DA9EA73D1D08D6AA0021F650 /* TableRowAction.swift */,
|
||||
DAC2D68E1C9D799E009E9C19 /* TableSection.swift */,
|
||||
DAC2D68D1C9D799E009E9C19 /* TableRowBuilder.swift */,
|
||||
DA9EA7341D06155E0021F650 /* HeightStrategy.swift */,
|
||||
|
|
@ -230,6 +233,7 @@
|
|||
DAC2D6901C9D799E009E9C19 /* TableDirector.swift in Sources */,
|
||||
DAC2D6921C9D799E009E9C19 /* TableSection.swift in Sources */,
|
||||
DA9EA7351D06155E0021F650 /* HeightStrategy.swift in Sources */,
|
||||
DA9EA73E1D08D6AA0021F650 /* TableRowAction.swift in Sources */,
|
||||
DA539CC61D01D44500368ACB /* TableRow.swift in Sources */,
|
||||
DA08A04F1CF3AB0C00BBF1F8 /* ConfigurableCell.swift in Sources */,
|
||||
DAC2D6911C9D799E009E9C19 /* TableRowBuilder.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -30,15 +30,22 @@ class MainController: UIViewController {
|
|||
|
||||
|
||||
|
||||
|
||||
let a = TableRowAction<String, StoryboardImageTableViewCell>(.Click) {
|
||||
(row) in
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
let row1 = TableRow<String, StoryboardImageTableViewCell>(item: "1")
|
||||
let row2 = TableRow<String, StoryboardImageTableViewCell>(item: "2")
|
||||
let row3 = TableRow<String, StoryboardImageTableViewCell>(item: "3")
|
||||
let row3 = TableRow<String, StoryboardImageTableViewCell>(item: "3", actions: [a])
|
||||
|
||||
|
||||
row1
|
||||
|
||||
.addAction(TableRowAction(.Click) { (row) in
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue