Merge pull request #2 from maxsokolov/develop

v0.2.0
This commit is contained in:
Max Sokolov 2015-12-07 00:36:29 +03:00
commit 48da5120e6
17 changed files with 258 additions and 92 deletions

View File

@ -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.1.0-blue.svg" alt="CocoaPods compatible" /></a>
<a href="https://cocoapods.org/pods/tablet"><img src="https://img.shields.io/badge/pod-0.2.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>
@ -18,7 +18,7 @@ Tablet respects cells reusability feature and it's type-safe. See the Usage sect
## Requirements
- iOS 8.0+
- Xcode 7.1+
- Xcode 7.0+
## Installation
@ -49,7 +49,7 @@ You may want to setup a very basic table view, without any custom cells. In that
import Tablet
let rowBuilder = TableRowBuilder<User, UITableViewCell>(items: [user1, user2, user3], id: "reusable_id")
.action(.configure) { data in
.action(.configure) { data -> Void in
data.cell?.textLabel?.text = data.item.username
data.cell?.detailTextLabel?.text = data.item.isActive ? "Active" : "Inactive"
@ -104,13 +104,13 @@ Tablet provides a chaining approach to handle actions from your cells:
import Tablet
let rowBuilder = TableRowBuilder<User, MyTableViewCell>(items: [user1, user2, user3], id: "reusable_id")
.action(.configure) { data in
.action(.configure) { data -> Void in
}
.action(.click) { data in
.action(.click) { data -> Void in
}
.action(.shouldHighlight) { data in
.action(.shouldHighlight) { data -> ReturnValue in
return false
}
@ -126,7 +126,7 @@ class MyTableViewCell : UITableViewCell {
@IBAction func buttonClicked(sender: UIButton) {
Action(key: kMyAction, sender: self, userInfo: nil).perform()
Action(key: kMyAction, sender: self, userInfo: nil).invoke()
}
}
```
@ -135,13 +135,13 @@ And receive this actions with your row builder:
import Tablet
let rowBuilder = TableConfigurableRowBuilder<User, MyTableViewCell>(items: users, id: "reusable_id", estimatedRowHeight: 42)
.action(.click) { data in
.action(.click) { data -> Void in
}
.action(.willDisplay) { data in
.action(.willDisplay) { data -> Void in
}
.action(kMyAction) { data in
.action(kMyAction) { data -> Void in
}
```
@ -159,18 +159,18 @@ extension TableDirector {
public func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
performAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
invokeAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
}
}
```
Catch your action with row builder:
```swift
let rowBuilder = TableConfigurableRowBuilder<User, MyTableViewCell>(items: users, estimatedRowHeight: 42)
.action(kTableDirectorDidEndDisplayingCell) { data in
.action(kTableDirectorDidEndDisplayingCell) { data -> Void in
}
```
You could also perform an action that returns a value.
You could also invoke an action that returns a value.
## License

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Tablet'
s.version = '0.1.0'
s.version = '0.2.0'
s.homepage = 'https://github.com/maxsokolov/tablet'
s.summary = 'Powerful type-safe tool for UITableView. Swift 2.0 is required.'

View File

@ -44,16 +44,6 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
NSNotificationCenter.defaultCenter().removeObserver(self)
}
// MARK: Sections manipulation
public func appendSection(section: TableSectionBuilder) {
sections.append(section)
}
public func appendSections(sections: [TableSectionBuilder]) {
self.sections.appendContentsOf(sections)
}
// MARK: Private methods
/**
@ -69,10 +59,10 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
return sections[indexPath.section].builderAtIndex(indexPath.row)!
}
public func performAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? {
public func invokeAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? {
let builder = builderAtIndexPath(indexPath)
return builder.0.performAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1)
return builder.0.invokeAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil)
}
internal func didReceiveAction(notification: NSNotification) {
@ -80,108 +70,146 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
if let action = notification.object as? Action, indexPath = tableView.indexPathForCell(action.cell) {
let builder = builderAtIndexPath(indexPath)
builder.0.performAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1)
builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: action.userInfo)
}
}
}
public extension TableDirector {
// MARK: UITableViewDataSource - configuration
public func numberOfSectionsInTableView(tableView: UITableView) -> Int {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sections.count
}
public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].numberOfRowsInSection
}
public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let builder = builderAtIndexPath(indexPath)
let cell = tableView.dequeueReusableCellWithIdentifier(builder.0.reusableIdentifier, forIndexPath: indexPath)
builder.0.performAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1)
builder.0.invokeAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil)
return cell
}
}
extension TableDirector {
public extension TableDirector {
// MARK: UITableViewDataSource - section setup
public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section].headerTitle
}
public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return sections[section].footerTitle
}
// MARK: UITableViewDelegate - section setup
public func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return sections[section].headerView
}
public func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return sections[section].footerView
}
public func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return sections[section].headerHeight
}
public func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return sections[section].footerHeight
}
}
extension TableDirector {
public extension TableDirector {
// MARK: UITableViewDelegate - actions
public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return builderAtIndexPath(indexPath).0.estimatedRowHeight
}
public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return performAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension
return invokeAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension
}
public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
if performAction(.click, cell: cell, indexPath: indexPath) != nil {
if invokeAction(.click, cell: cell, indexPath: indexPath) != nil {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else {
performAction(.select, cell: cell, indexPath: indexPath)
invokeAction(.select, cell: cell, indexPath: indexPath)
}
}
public func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
performAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath)
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
invokeAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath)
}
public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
performAction(.willDisplay, cell: cell, indexPath: indexPath)
invokeAction(.willDisplay, cell: cell, indexPath: indexPath)
}
public func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return performAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true
return invokeAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true
}
}
public extension TableDirector {
// MARK: Sections manipulation
public func appendSection(section: TableSectionBuilder) {
appendSections([section])
}
public func appendSections(sections: [TableSectionBuilder]) {
sections.forEach { $0.willMoveToDirector(tableView) }
self.sections.appendContentsOf(sections)
}
}
public func +=(left: TableDirector, right: RowBuilder) {
left.appendSection(TableSectionBuilder(rowBuilders: [right]))
}
public func +=(left: TableDirector, right: [RowBuilder]) {
left.appendSection(TableSectionBuilder(rowBuilders: right))
}
public func +=(left: TableDirector, right: TableSectionBuilder) {
left.appendSection(right)
}
public func +=(left: TableDirector, right: [TableSectionBuilder]) {
left.appendSections(right)
}

View File

@ -28,7 +28,7 @@ internal enum ActionHandler<I, C> {
case actionBlock((data: ActionData<I, C>) -> Void)
case actionReturnBlock((data: ActionData<I, C>) -> AnyObject?)
func call(data: ActionData<I, C>) -> AnyObject? {
func invoke(data: ActionData<I, C>) -> AnyObject? {
switch (self) {
case .actionBlock(let closure):
@ -56,34 +56,22 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
}
}
public init(item: I, id: String, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
public init(item: I, id: String? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
reusableIdentifier = id
reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? ""
self.estimatedRowHeight = estimatedRowHeight
items.append(item)
}
public init(items: [I]? = nil, id: String, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
public init(items: [I]? = nil, id: String? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
reusableIdentifier = id
reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? ""
self.estimatedRowHeight = estimatedRowHeight
if items != nil {
self.items.appendContentsOf(items!)
}
}
// MARK: Items manipulation
public func appendItems(items: [I]) {
self.items.appendContentsOf(items)
}
public func clear() {
items.removeAll()
}
// MARK: Chaining actions
@ -107,19 +95,39 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
// MARK: Triggers
public func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? {
public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]? = nil) -> AnyObject? {
if let action = actions[actionType.key] {
return action.call(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex))
return action.invoke(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex))
}
return nil
}
public func registerCell(inTableView tableView: UITableView) {
if tableView.dequeueReusableCellWithIdentifier(reusableIdentifier) != nil {
return
}
guard let resource = NSStringFromClass(C).componentsSeparatedByString(".").last else { return }
let bundle = NSBundle(forClass: C.self)
if let _ = bundle.pathForResource(resource, ofType: "nib") { // existing cell
tableView.registerNib(UINib(nibName: resource, bundle: bundle), forCellReuseIdentifier: reusableIdentifier)
} else {
tableView.registerClass(C.self, forCellReuseIdentifier: reusableIdentifier)
}
}
}
/**
Responsible for building configurable cells of given type and passing items to them.
*/
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
public init(item: I, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
super.init(item: item, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight)
@ -129,13 +137,28 @@ public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item ==
super.init(items: items, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight)
}
public override func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? {
public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]? = nil) -> AnyObject? {
switch actionType {
case .configure:
(cell as? C)?.configureWithItem(items[itemIndex])
default: break
}
return super.performAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex)
return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex)
}
}
public extension TableRowBuilder {
// MARK: Items manipulation
public func appendItems(items: [I]) {
self.items.appendContentsOf(items)
}
public func clear() {
items.removeAll()
}
}

View File

@ -27,6 +27,7 @@ import Foundation
*/
public class TableSectionBuilder {
internal weak var tableView: UITableView?
private var builders = [RowBuilder]()
public var headerTitle: String?
@ -45,23 +46,26 @@ public class TableSectionBuilder {
}
public init(headerTitle: String? = nil, footerTitle: String? = nil, rowBuilders: [RowBuilder]? = nil) {
self.headerTitle = headerTitle
self.footerTitle = footerTitle
if let initialRows = rowBuilders {
self.builders.appendContentsOf(initialRows)
builders.appendContentsOf(initialRows)
}
}
public init(headerView: UIView? = nil, headerHeight: CGFloat = UITableViewAutomaticDimension, footerView: UIView? = nil, footerHeight: CGFloat = UITableViewAutomaticDimension) {
self.headerView = headerView
self.headerHeight = headerHeight
self.footerView = footerView
self.footerHeight = footerHeight
}
}
internal extension TableSectionBuilder {
internal func builderAtIndex(var index: Int) -> (RowBuilder, Int)? {
@ -74,4 +78,28 @@ public class TableSectionBuilder {
return nil
}
internal func willMoveToDirector(tableView: UITableView) {
self.tableView = tableView
self.builders.forEach { $0.registerCell(inTableView: tableView) }
}
}
public extension TableSectionBuilder {
public func clear() {
builders.removeAll()
}
public func appendRowBuilder(rowBuilder: RowBuilder) {
appendRowBuilders([rowBuilder])
}
public func appendRowBuilders(rowBuilders: [RowBuilder]) {
if let tableView = tableView { rowBuilders.forEach { $0.registerCell(inTableView: tableView) } }
builders.appendContentsOf(rowBuilders)
}
}

View File

@ -86,7 +86,7 @@ public class Action {
self.userInfo = userInfo
}
public func perform() {
public func invoke() {
NSNotificationCenter.defaultCenter().postNotificationName(kActionPerformedNotificationKey, object: self)
}
@ -104,6 +104,14 @@ public protocol ConfigurableCell {
func configureWithItem(item: Item)
}
public extension ConfigurableCell where Self: UITableViewCell {
static func reusableIdentifier() -> String {
return NSStringFromClass(self).componentsSeparatedByString(".").last ?? ""
}
}
/**
A protocol that every row builder should follow.
A certain section can only works with row builders that respect this protocol.
@ -114,5 +122,6 @@ public protocol RowBuilder {
var reusableIdentifier: String { get }
var estimatedRowHeight: CGFloat { get }
func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject?
func registerCell(inTableView tableView: UITableView)
func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject?
}

View File

@ -18,6 +18,9 @@
DAB7EB351BEF787300D2AD5E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAB7EB331BEF787300D2AD5E /* LaunchScreen.storyboard */; };
DAB7EB3E1BEF78A400D2AD5E /* Tablet.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */; };
DAB7EB401BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */; };
DAED08F11C14DE7E006C04D8 /* MyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAED08F01C14DE7E006C04D8 /* MyTableViewCell.swift */; };
DAF003961C14DC0C0028C3D6 /* MyNibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */; };
DAF003981C14DC250028C3D6 /* MyNibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -34,6 +37,9 @@
DAB7EB361BEF787300D2AD5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tablet.swift; sourceTree = "<group>"; };
DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableTableViewCell.swift; sourceTree = "<group>"; };
DAED08F01C14DE7E006C04D8 /* MyTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyTableViewCell.swift; sourceTree = "<group>"; };
DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyNibTableViewCell.swift; sourceTree = "<group>"; };
DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MyNibTableViewCell.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -71,6 +77,9 @@
DAB7EB2C1BEF787300D2AD5E /* ViewController.swift */,
DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */,
DA1BCD101BF7388C00CC0479 /* CustomTableActions.swift */,
DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */,
DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */,
DAED08F01C14DE7E006C04D8 /* MyTableViewCell.swift */,
DAB7EB2E1BEF787300D2AD5E /* Main.storyboard */,
DAB7EB311BEF787300D2AD5E /* Assets.xcassets */,
DAB7EB331BEF787300D2AD5E /* LaunchScreen.storyboard */,
@ -150,6 +159,7 @@
buildActionMask = 2147483647;
files = (
DAB7EB351BEF787300D2AD5E /* LaunchScreen.storyboard in Resources */,
DAF003981C14DC250028C3D6 /* MyNibTableViewCell.xib in Resources */,
DAB7EB321BEF787300D2AD5E /* Assets.xcassets in Resources */,
DAB7EB301BEF787300D2AD5E /* Main.storyboard in Resources */,
);
@ -165,6 +175,8 @@
508B71841BF48DD300272920 /* TableSectionBuilder.swift in Sources */,
DAB7EB2D1BEF787300D2AD5E /* ViewController.swift in Sources */,
DAB7EB3E1BEF78A400D2AD5E /* Tablet.swift in Sources */,
DAED08F11C14DE7E006C04D8 /* MyTableViewCell.swift in Sources */,
DAF003961C14DC0C0028C3D6 /* MyNibTableViewCell.swift in Sources */,
508B71861BF48E0D00272920 /* TableRowBuilder.swift in Sources */,
DA1BCD0F1BF5472C00CC0479 /* TableDirector.swift in Sources */,
DAB7EB401BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift in Sources */,

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>

View File

@ -20,7 +20,7 @@
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="ovi-uI-31e">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<animations/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="cell" textLabel="Rrx-qY-GXL" style="IBUITableViewCellStyleDefault" id="MhM-yS-XTS">
<rect key="frame" x="0.0" y="114" width="600" height="44"/>
@ -34,7 +34,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
@ -42,7 +42,7 @@
</tableViewCellContentView>
<animations/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="configurable_cell" id="GPe-Vu-z5d" customClass="ConfigurableTableViewCell" customModule="TabletDemo" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="ConfigurableTableViewCell" id="GPe-Vu-z5d" customClass="ConfigurableTableViewCell" customModule="TabletDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="158" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="GPe-Vu-z5d" id="GMV-qL-pTv">
@ -66,7 +66,7 @@
<rect key="frame" x="92" y="12" width="498" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>

View File

@ -19,7 +19,7 @@ class ConfigurableTableViewCell: UITableViewCell, ConfigurableCell {
static func reusableIdentifier() -> String {
return "configurable_cell"
return "ConfigurableTableViewCell"
}
func configureWithItem(item: Item) {
@ -29,6 +29,6 @@ class ConfigurableTableViewCell: UITableViewCell, ConfigurableCell {
@IBAction func buttonClicked(sender: UIButton) {
Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).perform()
Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).invoke()
}
}

View File

@ -15,6 +15,6 @@ extension TableDirector {
public func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
performAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
invokeAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
}
}

View File

@ -0,0 +1,15 @@
//
// MyNibTableViewCell.swift
// TabletDemo
//
// Created by Max Sokolov on 07/12/15.
// Copyright © 2015 Tablet. All rights reserved.
//
import Foundation
import UIKit
class MyNibTableViewCell : UITableViewCell {
}

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="MyNibTableViewCell" id="ien-1l-Zfq" customClass="MyNibTableViewCell" customModule="TabletDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ien-1l-Zfq" id="Ddg-Z7-Dq5">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</tableViewCellContentView>
<animations/>
<color key="backgroundColor" red="1" green="0.54996175169999995" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<point key="canvasLocation" x="521" y="285"/>
</tableViewCell>
</objects>
</document>

View File

@ -0,0 +1,19 @@
//
// MyTableViewCell.swift
// TabletDemo
//
// Created by Max Sokolov on 07/12/15.
// Copyright © 2015 Tablet. All rights reserved.
//
import Foundation
import UIKit
class MyTableViewCell : UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
backgroundColor = UIColor.redColor()
}
}

View File

@ -53,8 +53,12 @@ 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 sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder])
let myRowBuilder = TableRowBuilder<Int, MyTableViewCell>(item: 0, id: "cellll")
tableDirector.appendSection(sectionBuilder)
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))
}
}