minor improvements
This commit is contained in:
parent
4a9ed7f4ff
commit
5ac120da0c
|
|
@ -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.4-blue.svg" alt="CocoaPods compatible" /></a>
|
||||
<a href="https://cocoapods.org/pods/tablet"><img src="https://img.shields.io/badge/pod-0.3.0-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.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.'
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -130,14 +130,17 @@ 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 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())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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<Int, UITableViewCell>(items: [1, 2, 3, 4], id: "cell")
|
||||
|
|
@ -33,7 +36,6 @@ class ViewController: UIViewController, UIScrollViewDelegate {
|
|||
print("end display: \(data.indexPath)")
|
||||
}
|
||||
|
||||
|
||||
let configurableRowBuilder = TableConfigurableRowBuilder<String, ConfigurableTableViewCell>(items: ["5", "6", "7", "8"])
|
||||
.action(.click) { data -> Void in
|
||||
|
||||
|
|
@ -50,18 +52,18 @@ class ViewController: UIViewController, UIScrollViewDelegate {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
.action(.configure) { (data) -> Void in
|
||||
.action(.configure) { data -> Void in
|
||||
|
||||
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 sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder, myRowBuilder])
|
||||
let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rows: [rowBuilder, configurableRowBuilder, myRowBuilder])
|
||||
|
||||
tableDirector += sectionBuilder
|
||||
|
||||
sectionBuilder.appendRowBuilder(TableRowBuilder<Int, MyNibTableViewCell>(item: 0))
|
||||
sectionBuilder.appendRow(TableRowBuilder<Int, MyNibTableViewCell>(item: 0))
|
||||
}
|
||||
|
||||
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue