diff --git a/README.md b/README.md index d23abe9..f565391 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

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

@@ -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(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(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(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(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 diff --git a/Tablet.podspec b/Tablet.podspec index de7a9f9..1dd195d 100644 --- a/Tablet.podspec +++ b/Tablet.podspec @@ -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.' diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index 30c6daf..cbe110c 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -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) } \ No newline at end of file diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index edd2854..54c9853 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 call(data: ActionData) -> AnyObject? { + func invoke(data: ActionData) -> AnyObject? { switch (self) { case .actionBlock(let closure): @@ -56,34 +56,22 @@ public class TableRowBuilder : 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 : 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 : TableRowBuilder { +public class TableConfigurableRowBuilder : TableRowBuilder { public init(item: I, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { super.init(item: item, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight) @@ -129,13 +137,28 @@ public class TableConfigurableRowBuilder 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() + } +} \ No newline at end of file diff --git a/Tablet/TableSectionBuilder.swift b/Tablet/TableSectionBuilder.swift index 4853b3e..55dfb11 100644 --- a/Tablet/TableSectionBuilder.swift +++ b/Tablet/TableSectionBuilder.swift @@ -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) + } } \ No newline at end of file diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index 3331c53..8b2c35e 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -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? } \ No newline at end of file diff --git a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj index f241c66..c043d8b 100644 --- a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj +++ b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj @@ -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 = ""; }; DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tablet.swift; sourceTree = ""; }; DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableTableViewCell.swift; sourceTree = ""; }; + DAED08F01C14DE7E006C04D8 /* MyTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyTableViewCell.swift; sourceTree = ""; }; + DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyNibTableViewCell.swift; sourceTree = ""; }; + DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MyNibTableViewCell.xib; sourceTree = ""; }; /* 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 */, 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 72a945c..1faa2df 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.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 37a26d5..da29aef 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.xcodeproj/xcuserdata/max.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TabletDemo/TabletDemo.xcodeproj/xcuserdata/max.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/TabletDemo/TabletDemo.xcodeproj/xcuserdata/max.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/TabletDemo/TabletDemo/Base.lproj/Main.storyboard b/TabletDemo/TabletDemo/Base.lproj/Main.storyboard index 2bd0123..65ef436 100644 --- a/TabletDemo/TabletDemo/Base.lproj/Main.storyboard +++ b/TabletDemo/TabletDemo/Base.lproj/Main.storyboard @@ -20,7 +20,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -66,7 +66,7 @@ - + diff --git a/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift b/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift index 07be0a2..05da583 100644 --- a/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift +++ b/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift @@ -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() } } \ No newline at end of file diff --git a/TabletDemo/TabletDemo/CustomTableActions.swift b/TabletDemo/TabletDemo/CustomTableActions.swift index c586a75..5466099 100644 --- a/TabletDemo/TabletDemo/CustomTableActions.swift +++ b/TabletDemo/TabletDemo/CustomTableActions.swift @@ -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) } } \ No newline at end of file diff --git a/TabletDemo/TabletDemo/MyNibTableViewCell.swift b/TabletDemo/TabletDemo/MyNibTableViewCell.swift new file mode 100644 index 0000000..4888fb9 --- /dev/null +++ b/TabletDemo/TabletDemo/MyNibTableViewCell.swift @@ -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 { + + +} \ No newline at end of file diff --git a/TabletDemo/TabletDemo/MyNibTableViewCell.xib b/TabletDemo/TabletDemo/MyNibTableViewCell.xib new file mode 100644 index 0000000..02401db --- /dev/null +++ b/TabletDemo/TabletDemo/MyNibTableViewCell.xib @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TabletDemo/TabletDemo/MyTableViewCell.swift b/TabletDemo/TabletDemo/MyTableViewCell.swift new file mode 100644 index 0000000..9f03cea --- /dev/null +++ b/TabletDemo/TabletDemo/MyTableViewCell.swift @@ -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() + } +} \ No newline at end of file diff --git a/TabletDemo/TabletDemo/ViewController.swift b/TabletDemo/TabletDemo/ViewController.swift index ed353d5..5260cd0 100644 --- a/TabletDemo/TabletDemo/ViewController.swift +++ b/TabletDemo/TabletDemo/ViewController.swift @@ -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(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(item: 0)) } } \ No newline at end of file