diff --git a/README.md b/README.md index 16db304..9ee6c5c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

Swift 2 compatible Platform iOS -CocoaPods compatible +CocoaPods compatible License: MIT

diff --git a/Tablet.podspec b/Tablet.podspec index d6f53a6..be5eb30 100644 --- a/Tablet.podspec +++ b/Tablet.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Tablet' - s.version = '0.2.2' + s.version = '0.2.3' 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 116ed75..bdec698 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -28,6 +28,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate private weak var tableView: UITableView! private var sections = [TableSectionBuilder]() + public var scrollDelegate: UIScrollViewDelegate? public init(tableView: UITableView) { super.init() @@ -73,6 +74,14 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: action.userInfo) } } + + public override func respondsToSelector(selector: Selector) -> Bool { + return super.respondsToSelector(selector) || scrollDelegate?.respondsToSelector(selector) == true + } + + public override func forwardingTargetForSelector(selector: Selector) -> AnyObject? { + return scrollDelegate?.respondsToSelector(selector) == true ? scrollDelegate : super.forwardingTargetForSelector(selector) + } } public extension TableDirector { diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index 8579f68..d3a3b8b 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -28,7 +28,7 @@ internal enum ActionHandler { case actionBlock((data: ActionData) -> Void) case actionReturnBlock((data: ActionData) -> AnyObject?) - func invoke(data: ActionData) -> AnyObject? { + func invoke(data: ActionData) -> ReturnValue { switch (self) { case .actionBlock(let closure): @@ -56,14 +56,14 @@ public class TableRowBuilder : RowBuilder { } } - public init(item: I, id: String? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { + public init(item: I, id: String? = nil, estimatedRowHeight: CGFloat) { reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "" self.estimatedRowHeight = estimatedRowHeight items.append(item) } - public init(items: [I]? = nil, id: String? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { + public init(items: [I]? = nil, id: String? = nil, estimatedRowHeight: CGFloat) { reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "" self.estimatedRowHeight = estimatedRowHeight @@ -129,11 +129,11 @@ public class TableRowBuilder : RowBuilder { */ public class TableConfigurableRowBuilder : TableRowBuilder { - public init(item: I, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { + public init(item: I, estimatedRowHeight: CGFloat) { super.init(item: item, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight) } - public init(items: [I]? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { + public init(items: [I]? = nil, estimatedRowHeight: CGFloat) { super.init(items: items, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight) } diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index ce40387..ac0e9a0 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -109,7 +109,7 @@ public extension ConfigurableCell where Self: UITableViewCell { static func reusableIdentifier() -> String { - return NSStringFromClass(self).componentsSeparatedByString(".").last ?? "" + return String(self.dynamicType).componentsSeparatedByString(".").last ?? "" } } diff --git a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate index 0cc2ecd..dc4bb6a 100644 Binary files a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate and b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TabletDemo/TabletDemo/ViewController.swift b/TabletDemo/TabletDemo/ViewController.swift index 1c20338..50d971f 100644 --- a/TabletDemo/TabletDemo/ViewController.swift +++ b/TabletDemo/TabletDemo/ViewController.swift @@ -8,7 +8,7 @@ import UIKit -class ViewController: UIViewController { +class ViewController: UIViewController, UIScrollViewDelegate { @IBOutlet weak var tableView: UITableView! var tableDirector: TableDirector! @@ -17,8 +17,9 @@ class ViewController: UIViewController { super.viewDidLoad() tableDirector = TableDirector(tableView: tableView) + tableDirector.scrollDelegate = self - let rowBuilder = TableRowBuilder(items: [1, 2, 3, 4], id: "cell") + let rowBuilder = TableRowBuilder(items: [1, 2, 3, 4], id: "cell", estimatedRowHeight: 44) .action(.configure) { data in data.cell?.textLabel?.text = "\(data.item)" @@ -54,12 +55,16 @@ class ViewController: UIViewController { data.cell!.contentLabel.text = "Tablet is a super lightweight yet powerful generic library that handles a complexity of UITableView's datasource and delegate methods in a Swift environment. Tablet's goal is to provide an easiest way to create complex table views. With Tablet you don't have to write a messy code of switch or if statements when you deal with bunch of different cells in different sections." } - let myRowBuilder = TableRowBuilder(item: 0, id: "cellll") + let myRowBuilder = TableRowBuilder(item: 0, id: "cellll", estimatedRowHeight: 44) let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder, myRowBuilder]) tableDirector += sectionBuilder - sectionBuilder.appendRowBuilder(TableRowBuilder(item: 0)) + sectionBuilder.appendRowBuilder(TableRowBuilder(item: 0, estimatedRowHeight: 44)) + } + + func scrollViewWillBeginDragging(scrollView: UIScrollView) { + print("begin dragging") } } \ No newline at end of file