diff --git a/README.md b/README.md index 84a933e..d6086ef 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@
diff --git a/Tablet.podspec b/Tablet.podspec index 5ab2bfc..c285709 100644 --- a/Tablet.podspec +++ b/Tablet.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Tablet' - s.version = '0.2.5' + s.version = '0.3.0' s.homepage = 'https://github.com/maxsokolov/tablet' s.summary = 'Powerful type-safe tool for UITableView. Swift 2.0 is required.' diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index 932592a..74bd1f2 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -37,7 +37,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate self.tableView.delegate = self self.tableView.dataSource = self - NSNotificationCenter.defaultCenter().addObserver(self, selector: "didReceiveAction:", name: kActionPerformedNotificationKey, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: "didReceiveAction:", name: TabletNotifications.CellAction, object: nil) } deinit { @@ -168,7 +168,7 @@ public extension TableDirector { func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { - return invokeAction(.willSelect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? NSIndexPath ?? indexPath + return invokeAction(.willSelect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? NSIndexPath } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { @@ -218,21 +218,17 @@ public extension TableDirector { } public func +=(left: TableDirector, right: RowBuilder) { - - left.appendSection(TableSectionBuilder(rowBuilders: [right])) + left.appendSection(TableSectionBuilder(rows: [right])) } public func +=(left: TableDirector, right: [RowBuilder]) { - - left.appendSection(TableSectionBuilder(rowBuilders: right)) + left.appendSection(TableSectionBuilder(rows: right)) } public func +=(left: TableDirector, right: TableSectionBuilder) { - left.appendSection(right) } public func +=(left: TableDirector, right: [TableSectionBuilder]) { - left.appendSections(right) } \ No newline at end of file diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index e9889bc..fcf8b8c 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -130,14 +130,17 @@ public class TableRowBuilder : RowBuilder { public class TableConfigurableRowBuilder : TableRowBuilder { public override var estimatedRowHeight: Float { + return C.estimatedHeight() } public init(item: I) { + super.init(item: item, id: C.reusableIdentifier()) } public init(items: [I]? = nil) { + super.init(items: items, id: C.reusableIdentifier()) } diff --git a/Tablet/TableSectionBuilder.swift b/Tablet/TableSectionBuilder.swift index 5912ff0..5bfe19c 100644 --- a/Tablet/TableSectionBuilder.swift +++ b/Tablet/TableSectionBuilder.swift @@ -45,12 +45,12 @@ public class TableSectionBuilder { return builders.reduce(0) { $0 + $1.numberOfRows } } - public init(headerTitle: String? = nil, footerTitle: String? = nil, rowBuilders: [RowBuilder]? = nil) { + public init(headerTitle: String? = nil, footerTitle: String? = nil, rows: [RowBuilder]? = nil) { self.headerTitle = headerTitle self.footerTitle = footerTitle - if let initialRows = rowBuilders { + if let initialRows = rows { builders.appendContentsOf(initialRows) } } @@ -88,16 +88,14 @@ internal extension TableSectionBuilder { public extension TableSectionBuilder { public func clear() { - builders.removeAll() } - public func appendRowBuilder(rowBuilder: RowBuilder) { - - appendRowBuilders([rowBuilder]) + public func appendRow(row: RowBuilder) { + appendRows([row]) } - public func appendRowBuilders(rowBuilders: [RowBuilder]) { + public func appendRows(rowBuilders: [RowBuilder]) { if let tableView = tableView { rowBuilders.forEach { $0.registerCell(inTableView: tableView) } } builders.appendContentsOf(rowBuilders) @@ -105,11 +103,9 @@ public extension TableSectionBuilder { } public func +=(left: TableSectionBuilder, right: RowBuilder) { - - left.appendRowBuilder(right) + left.appendRow(right) } public func +=(left: TableSectionBuilder, right: [RowBuilder]) { - - left.appendRowBuilders(right) + left.appendRows(right) } \ No newline at end of file diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index e287852..a4ceb60 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -21,7 +21,9 @@ import UIKit import Foundation -internal let kActionPerformedNotificationKey = "_action" +internal struct TabletNotifications { + static let CellAction = "_cellaction" +} /** The actions that Tablet provides. @@ -89,7 +91,7 @@ public class Action { public func invoke() { - NSNotificationCenter.defaultCenter().postNotificationName(kActionPerformedNotificationKey, object: self) + NSNotificationCenter.defaultCenter().postNotificationName(TabletNotifications.CellAction, object: self) } } diff --git a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 17fa8b2..9bdfdde 100644 Binary files a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TabletDemo/TabletDemo/ViewController.swift b/TabletDemo/TabletDemo/ViewController.swift index fa02d6c..805aad2 100644 --- a/TabletDemo/TabletDemo/ViewController.swift +++ b/TabletDemo/TabletDemo/ViewController.swift @@ -10,13 +10,16 @@ import UIKit class ViewController: UIViewController, UIScrollViewDelegate { - @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var tableView: UITableView! { + didSet { + tableDirector = TableDirector(tableView: tableView) + } + } var tableDirector: TableDirector! override func viewDidLoad() { super.viewDidLoad() - tableDirector = TableDirector(tableView: tableView) tableDirector.scrollDelegate = self let rowBuilder = TableRowBuilder