From 21f131bb19df1c4189d5ffb11c8614b0cfcf56e5 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Tue, 7 Jun 2016 21:41:57 +0300 Subject: [PATCH] add RowConfigurable protocol --- Tablet/RowBuilder.swift | 7 ++- Tablet/TableDirector.swift | 4 +- Tablet/TableDynamicRowBuilder.swift | 45 ++++++++++++++++++- Tablet/TableRowBuilder.swift | 7 +++ .../Controllers/MainController.swift | 13 +++--- 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Tablet/RowBuilder.swift b/Tablet/RowBuilder.swift index d10b3cf..773d8d1 100644 --- a/Tablet/RowBuilder.swift +++ b/Tablet/RowBuilder.swift @@ -26,7 +26,12 @@ public protocol RowHeightCalculatable { func estimatedRowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat } -public protocol RowBuilder: RowHeightCalculatable { +public protocol RowConfigurable { + + func configure(cell: UITableViewCell, path: NSIndexPath, index: Int) +} + +public protocol RowBuilder: RowConfigurable, RowHeightCalculatable { var tableDirector: TableDirector? { get } diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index 72d3a9f..5d0a028 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -119,8 +119,8 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate cell.layoutIfNeeded() } - builder.0.invoke(action: .configure, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil) - + builder.0.configure(cell, path: indexPath, index: builder.1) + return cell } diff --git a/Tablet/TableDynamicRowBuilder.swift b/Tablet/TableDynamicRowBuilder.swift index 25c6455..5e2a0a4 100644 --- a/Tablet/TableDynamicRowBuilder.swift +++ b/Tablet/TableDynamicRowBuilder.swift @@ -22,12 +22,18 @@ import UIKit public protocol RowItemable { + var reusableIdentifier: String { get } + func configure(cell: UITableViewCell) } public class RowItem: RowItemable { public let item: DataType + + public var reusableIdentifier: String { + return CellType.reusableIdentifier() + } public init(item: DataType) { self.item = item @@ -38,7 +44,7 @@ public class RowItem String { + return items[index].reusableIdentifier + } + + public func willUpdateDirector(director: TableDirector?) { + + } + + public func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject : AnyObject]?) -> AnyObject? { + + return nil + } + + // MARK: - RowHeightCalculatable - + + public func rowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat { + return UITableViewAutomaticDimension + } + + public func estimatedRowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat { + return 0 //CellType.estimatedHeight() + } } \ No newline at end of file diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index b5f2d53..752e238 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -64,6 +64,13 @@ public class TableRowBuilder) { diff --git a/TabletDemo/Classes/Presentation/Controllers/MainController.swift b/TabletDemo/Classes/Presentation/Controllers/MainController.swift index d8480ba..89d29cb 100644 --- a/TabletDemo/Classes/Presentation/Controllers/MainController.swift +++ b/TabletDemo/Classes/Presentation/Controllers/MainController.swift @@ -26,17 +26,15 @@ class MainController: UIViewController { self.performSegueWithIdentifier("headerfooter", sender: nil) } + let section = TableSectionBuilder(headerTitle: "", footerTitle: "", rows: [rowBuilder]) - /*let rows2 = TableRowBuilder(items: ["1", "1", "1", "1"]) - - let cellItem = RowItem(item: "1") + let cellItem = RowItem(item: "1") let cellItem2 = RowItem(item: "1") - let cellItem3 = RowItem(item: "1") @@ -45,7 +43,7 @@ class MainController: UIViewController { let b = TableDynamicRowBuilder(items: [cellItem, cellItem2, cellItem3]) - rowBuilder + /*rowBuilder .addAction(TableRowAction(type: .Click) { (data) in @@ -55,8 +53,7 @@ class MainController: UIViewController { .delete(indexes: [0], animated: .None) .insert(["2"], atIndex: 0, animated: .None) .update(index: 0, item: "", animated: .None) - .move([1, 2], toIndexes: [3, 4])*/ - + .move([1, 2], toIndexes: [3, 4]) @@ -71,7 +68,7 @@ class MainController: UIViewController { //tableView.insertSections([], withRowAnimation: .None) //tableDirector.performBatchUpdates { - //} + //}*/ tableDirector.append(section: section) }