diff --git a/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 1fef06b..7edcc6a 100644 Binary files a/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index 59afd53..567c3fe 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -40,6 +40,30 @@ enum ActionHandler { } } +public class RowBuilder : NSObject { + + public private(set) var reusableIdentifier: String + public var numberOfRows: Int { + return 0 + } + public var estimatedRowHeight: Float { + return 44 + } + + init(id: String) { + reusableIdentifier = id + } + + // MARK: internal methods, must be overriden in subclass + + func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { + return nil + } + + func registerCell(inTableView tableView: UITableView) { + } +} + /** Responsible for building cells of given type and passing items to them. */ @@ -48,25 +72,18 @@ public class TableRowBuilder : RowBuilder { private var actions = Dictionary>() private var items = [I]() - public var reusableIdentifier: String - public var estimatedRowHeight: Float { - return 44 - } - public var numberOfRows: Int { - get { - return items.count - } + public override var numberOfRows: Int { + return items.count } public init(item: I, id: String? = nil) { - - reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "" + super.init(id: id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "") + items.append(item) } public init(items: [I]? = nil, id: String? = nil) { - - reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "" + super.init(id: id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "") if items != nil { self.items.appendContentsOf(items!) @@ -95,7 +112,7 @@ public class TableRowBuilder : RowBuilder { // MARK: Triggers - public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { + override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { if let action = actions[actionType.key] { return action.invoke(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex, userInfo: userInfo)) @@ -103,7 +120,7 @@ public class TableRowBuilder : RowBuilder { return nil } - public func registerCell(inTableView tableView: UITableView) { + override func registerCell(inTableView tableView: UITableView) { if tableView.dequeueReusableCellWithIdentifier(reusableIdentifier) != nil { return @@ -128,23 +145,20 @@ public class TableRowBuilder : RowBuilder { Responsible for building configurable cells of given type and passing items to them. */ public class TableConfigurableRowBuilder : TableRowBuilder { - + 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()) } - public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { + override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { switch actionType { case .configure: @@ -160,22 +174,18 @@ public extension TableRowBuilder { // MARK: Items manipulation public func appendItems(items: [I]) { - self.items.appendContentsOf(items) } public func clear() { - items.removeAll() } } public func +=(left: TableRowBuilder, right: I) { - left.appendItems([right]) } public func +=(left: TableRowBuilder, right: [I]) { - left.appendItems(right) } \ No newline at end of file diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index 3a4eaa0..9c344d0 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -22,7 +22,7 @@ import UIKit import Foundation struct TabletNotifications { - static let CellAction = "_cellaction" + static let CellAction = "TabletNotificationsCellAction" } /** @@ -113,21 +113,6 @@ public protocol ConfigurableCell { 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. -*/ -public protocol RowBuilder { - - var numberOfRows: Int { get } - var reusableIdentifier: String { get } - var estimatedRowHeight: Float { get } - - 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/Classes/Presentation/Main/ViewControllers/MainViewController.swift b/TabletDemo/Classes/Presentation/Main/ViewControllers/MainViewController.swift index 3831c57..3bb415a 100644 --- a/TabletDemo/Classes/Presentation/Main/ViewControllers/MainViewController.swift +++ b/TabletDemo/Classes/Presentation/Main/ViewControllers/MainViewController.swift @@ -25,5 +25,9 @@ class MainViewController : UITableViewController { data.cell?.accessoryType = .DisclosureIndicator data.cell?.textLabel?.text = "\(data.item)" } + .action(.click) { data -> Void in + + + } } } \ No newline at end of file