commit
bc68416818
|
|
@ -3,7 +3,7 @@
|
|||
<p align="left">
|
||||
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/Swift2-compatible-4BC51D.svg?style=flat" alt="Swift 2 compatible" /></a>
|
||||
<img src="https://img.shields.io/badge/platform-iOS-blue.svg?style=flat" alt="Platform iOS" />
|
||||
<a href="https://cocoapods.org/pods/tablet"><img src="https://img.shields.io/badge/pod-0.2.1-blue.svg" alt="CocoaPods compatible" /></a>
|
||||
<a href="https://cocoapods.org/pods/tablet"><img src="https://img.shields.io/badge/pod-0.2.3-blue.svg" alt="CocoaPods compatible" /></a>
|
||||
<a href="https://raw.githubusercontent.com/maxsokolov/tablet/master/LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a>
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -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.'
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ internal enum ActionHandler<I, C> {
|
|||
case actionBlock((data: ActionData<I, C>) -> Void)
|
||||
case actionReturnBlock((data: ActionData<I, C>) -> AnyObject?)
|
||||
|
||||
func invoke(data: ActionData<I, C>) -> AnyObject? {
|
||||
func invoke(data: ActionData<I, C>) -> ReturnValue {
|
||||
|
||||
switch (self) {
|
||||
case .actionBlock(let closure):
|
||||
|
|
@ -56,14 +56,14 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : 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<I, C where C: UITableViewCell> : RowBuilder {
|
|||
*/
|
||||
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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<Int, UITableViewCell>(items: [1, 2, 3, 4], id: "cell")
|
||||
let rowBuilder = TableRowBuilder<Int, UITableViewCell>(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<Int, MyTableViewCell>(item: 0, id: "cellll")
|
||||
let myRowBuilder = TableRowBuilder<Int, MyTableViewCell>(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<Int, MyNibTableViewCell>(item: 0))
|
||||
sectionBuilder.appendRowBuilder(TableRowBuilder<Int, MyNibTableViewCell>(item: 0, estimatedRowHeight: 44))
|
||||
}
|
||||
|
||||
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
|
||||
print("begin dragging")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue