remove row builder
This commit is contained in:
parent
272d238a2a
commit
1e4f76e04f
|
|
@ -70,11 +70,11 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
|||
|
||||
func didReceiveAction(notification: NSNotification) {
|
||||
|
||||
if let action = notification.object as? Action, indexPath = tableView?.indexPathForCell(action.cell) {
|
||||
//if let action = notification.object as? Action, indexPath = tableView?.indexPathForCell(action.cell) {
|
||||
|
||||
//let builder = builderAtIndexPath(indexPath)
|
||||
//builder.0.invoke(action: .custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: notification.userInfo)
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
// MARK: - Height
|
||||
|
|
@ -175,17 +175,22 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
|||
|
||||
// MARK: - Sections manipulation -
|
||||
|
||||
public func append(section section: TableSection) {
|
||||
public func append(section section: TableSection) -> Self {
|
||||
|
||||
append(sections: [section])
|
||||
return self
|
||||
}
|
||||
|
||||
public func append(sections sections: [TableSection]) {
|
||||
public func append(sections sections: [TableSection]) -> Self {
|
||||
|
||||
sections.forEach { $0.tableDirector = self }
|
||||
self.sections.appendContentsOf(sections)
|
||||
return self
|
||||
}
|
||||
|
||||
public func clear() {
|
||||
public func clear() -> Self {
|
||||
|
||||
sections.removeAll()
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,6 @@
|
|||
DA9EA7741D0B68460021F650 /* TableDirector.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA76B1D0B68460021F650 /* TableDirector.swift */; };
|
||||
DA9EA7751D0B68460021F650 /* TableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA76C1D0B68460021F650 /* TableRow.swift */; };
|
||||
DA9EA7761D0B68460021F650 /* TableRowAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA76D1D0B68460021F650 /* TableRowAction.swift */; };
|
||||
DA9EA7771D0B68460021F650 /* TableRowBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA76E1D0B68460021F650 /* TableRowBuilder.swift */; };
|
||||
DA9EA7781D0B68460021F650 /* TableSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA76F1D0B68460021F650 /* TableSection.swift */; };
|
||||
DA9EA7791D0B68460021F650 /* Tablet.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA7701D0B68460021F650 /* Tablet.swift */; };
|
||||
DA9EA7801D0B689C0021F650 /* TableKit.h in Headers */ = {isa = PBXBuildFile; fileRef = DA9EA77E1D0B689C0021F650 /* TableKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
|
@ -27,7 +26,6 @@
|
|||
DA9EA76B1D0B68460021F650 /* TableDirector.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDirector.swift; sourceTree = "<group>"; };
|
||||
DA9EA76C1D0B68460021F650 /* TableRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRow.swift; sourceTree = "<group>"; };
|
||||
DA9EA76D1D0B68460021F650 /* TableRowAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRowAction.swift; sourceTree = "<group>"; };
|
||||
DA9EA76E1D0B68460021F650 /* TableRowBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRowBuilder.swift; sourceTree = "<group>"; };
|
||||
DA9EA76F1D0B68460021F650 /* TableSection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableSection.swift; sourceTree = "<group>"; };
|
||||
DA9EA7701D0B68460021F650 /* Tablet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tablet.swift; sourceTree = "<group>"; };
|
||||
DA9EA77D1D0B689C0021F650 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
|
@ -65,14 +63,13 @@
|
|||
DA9EA7671D0B68340021F650 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
DA9EA76B1D0B68460021F650 /* TableDirector.swift */,
|
||||
DA9EA76F1D0B68460021F650 /* TableSection.swift */,
|
||||
DA9EA76C1D0B68460021F650 /* TableRow.swift */,
|
||||
DA9EA76D1D0B68460021F650 /* TableRowAction.swift */,
|
||||
DA9EA7681D0B68460021F650 /* ConfigurableCell.swift */,
|
||||
DA9EA7691D0B68460021F650 /* HeightStrategy.swift */,
|
||||
DA9EA76A1D0B68460021F650 /* Operators.swift */,
|
||||
DA9EA76B1D0B68460021F650 /* TableDirector.swift */,
|
||||
DA9EA76C1D0B68460021F650 /* TableRow.swift */,
|
||||
DA9EA76D1D0B68460021F650 /* TableRowAction.swift */,
|
||||
DA9EA76E1D0B68460021F650 /* TableRowBuilder.swift */,
|
||||
DA9EA76F1D0B68460021F650 /* TableSection.swift */,
|
||||
DA9EA7701D0B68460021F650 /* Tablet.swift */,
|
||||
);
|
||||
name = Classes;
|
||||
|
|
@ -171,7 +168,6 @@
|
|||
DA9EA7751D0B68460021F650 /* TableRow.swift in Sources */,
|
||||
DA9EA7761D0B68460021F650 /* TableRowAction.swift in Sources */,
|
||||
DA9EA7741D0B68460021F650 /* TableDirector.swift in Sources */,
|
||||
DA9EA7771D0B68460021F650 /* TableRowBuilder.swift in Sources */,
|
||||
DA9EA7791D0B68460021F650 /* Tablet.swift in Sources */,
|
||||
DA9EA7731D0B68460021F650 /* Operators.swift in Sources */,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,168 +0,0 @@
|
|||
//
|
||||
// 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 typealias ReturnValue = AnyObject?
|
||||
|
||||
/**
|
||||
Responsible for building cells of given type and passing items to them.
|
||||
*/
|
||||
/*public class TableRowBuilder<DataType, CellType: ConfigurableCell where CellType.T == DataType, CellType: UITableViewCell> : RowBuilder {
|
||||
|
||||
public private(set) weak var tableDirector: TableDirector?
|
||||
private var heightStrategy: HeightStrategy?
|
||||
|
||||
private var actions = [String: ActionHandler<DataType, CellType>]()
|
||||
private var items = [DataType]()
|
||||
|
||||
public func reusableIdentifier(_: Int) -> String {
|
||||
return CellType.reusableIdentifier()
|
||||
}
|
||||
|
||||
public var numberOfRows: Int {
|
||||
return items.count
|
||||
}
|
||||
|
||||
// MARK: - Initializers -
|
||||
|
||||
public init(item: DataType) {
|
||||
items.append(item)
|
||||
}
|
||||
|
||||
public init(items: [DataType]? = nil) {
|
||||
|
||||
if let items = items {
|
||||
self.items.appendContentsOf(items)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - RowHeightCalculatable -
|
||||
|
||||
public func rowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat {
|
||||
return CellType.defaultHeight() ?? heightStrategy?.height(item(index: index), indexPath: indexPath, cell: CellType.self) ?? UITableViewAutomaticDimension
|
||||
}
|
||||
|
||||
public func estimatedRowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat {
|
||||
return CellType.estimatedHeight()
|
||||
}
|
||||
|
||||
// MARK: - RowConfigurable -
|
||||
|
||||
public func configure(cell: UITableViewCell, path: NSIndexPath, index: Int) {
|
||||
|
||||
(cell as? CellType)?.configure(items[index])
|
||||
}
|
||||
|
||||
// MARK: - Chaining actions -
|
||||
|
||||
public func addAction(action: TableRowAction<DataType, CellType>) {
|
||||
|
||||
}
|
||||
|
||||
public func action(key: String, handler: (data: ActionData<DataType, CellType>) -> Void) -> Self {
|
||||
|
||||
actions[key] = .Handler(handler)
|
||||
return self
|
||||
}
|
||||
|
||||
public func action(type: ActionType, handler: (data: ActionData<DataType, CellType>) -> Void) -> Self {
|
||||
|
||||
actions[type.key] = .Handler(handler)
|
||||
return self
|
||||
}
|
||||
|
||||
public func valueAction(type: ActionType, handler: (data: ActionData<DataType, CellType>) -> ReturnValue) -> Self {
|
||||
|
||||
actions[type.key] = .ValueHandler(handler)
|
||||
return self
|
||||
}
|
||||
|
||||
public func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? {
|
||||
|
||||
if case .configure = action {
|
||||
(cell as? CellType)?.configure(item(index: itemIndex))
|
||||
}
|
||||
|
||||
if let action = actions[action.key] {
|
||||
return action.invoke(ActionData(cell: cell as? CellType, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex, userInfo: userInfo))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private func registerCell(inTableView tableView: UITableView) {
|
||||
|
||||
if tableView.dequeueReusableCellWithIdentifier(reusableIdentifier(0)) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
let resource = String(CellType)
|
||||
let bundle = NSBundle(forClass: CellType.self)
|
||||
|
||||
if let _ = bundle.pathForResource(resource, ofType: "nib") { // existing cell
|
||||
tableView.registerNib(UINib(nibName: resource, bundle: bundle), forCellReuseIdentifier: reusableIdentifier(0))
|
||||
} else {
|
||||
tableView.registerClass(CellType.self, forCellReuseIdentifier: reusableIdentifier(0))
|
||||
}
|
||||
}
|
||||
|
||||
public func willUpdateDirector(director: TableDirector?) {
|
||||
tableDirector = director
|
||||
|
||||
heightStrategy = PrototypeHeightStrategy()
|
||||
heightStrategy?.tableView = director?.tableView
|
||||
}
|
||||
|
||||
// MARK: - Items manipulation -
|
||||
|
||||
public func delete(indexes indexes: [Int], animated: UITableViewRowAnimation) -> Self {
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
public func insert(items: [DataType], atIndex index: Int, animated: UITableViewRowAnimation) -> Self {
|
||||
|
||||
self.items.insertContentsOf(items, at: index)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
public func move(indexes: [Int], toIndexes: [Int]) -> Self {
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
public func update(index index: Int, item: DataType, animated: UITableViewRowAnimation) -> Self {
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
public func item(index index: Int) -> DataType {
|
||||
return items[index]
|
||||
}
|
||||
|
||||
public func append(items items: [DataType]) {
|
||||
self.items.appendContentsOf(items)
|
||||
}
|
||||
|
||||
public func clear() {
|
||||
items.removeAll()
|
||||
}
|
||||
}*/
|
||||
|
|
@ -30,7 +30,7 @@ struct TabletNotifications {
|
|||
A custom action that you can trigger from your cell.
|
||||
You can eacily catch actions using a chaining manner with your row builder.
|
||||
*/
|
||||
public class Action {
|
||||
public class TableCellAction {
|
||||
|
||||
/// The cell that triggers an action.
|
||||
public let cell: UITableViewCell
|
||||
|
|
|
|||
|
|
@ -58,8 +58,7 @@ class MainController: UIViewController {
|
|||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
let section = TableSection(headerTitle: "", footerTitle: "", rows: [row1, row2, row3])
|
||||
|
||||
tableDirector += [section]
|
||||
|
|
|
|||
Loading…
Reference in New Issue