diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index 59dccca..7d51a48 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -60,10 +60,10 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate // MARK: Public - public func invokeAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? { + public func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? { let builder = builderAtIndexPath(indexPath) - return builder.0.invokeAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil) + return builder.0.invoke(action: action, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil) } public override func respondsToSelector(selector: Selector) -> Bool { @@ -81,7 +81,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate if let action = notification.object as? Action, indexPath = tableView.indexPathForCell(action.cell) { let builder = builderAtIndexPath(indexPath) - builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: notification.userInfo) + builder.0.invoke(action: .custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: notification.userInfo) } } } @@ -109,7 +109,7 @@ public extension TableDirector { cell.layoutIfNeeded() } - builder.0.invokeAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil) + builder.0.invoke(action: .configure, cell: cell, indexPath: indexPath, itemIndex: builder.1, userInfo: nil) return cell } @@ -155,7 +155,7 @@ public extension TableDirector { } func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { - return invokeAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension + return invoke(action: .height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension } /*func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { @@ -167,23 +167,23 @@ public extension TableDirector { let cell = tableView.cellForRowAtIndexPath(indexPath) - if invokeAction(.click, cell: cell, indexPath: indexPath) != nil { + if invoke(action: .click, cell: cell, indexPath: indexPath) != nil { tableView.deselectRowAtIndexPath(indexPath, animated: true) } else { - invokeAction(.select, cell: cell, indexPath: indexPath) + invoke(action: .select, cell: cell, indexPath: indexPath) } } func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { - invokeAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) + invoke(action: .deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) } func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { - invokeAction(.willDisplay, cell: cell, indexPath: indexPath) + invoke(action: .willDisplay, cell: cell, indexPath: indexPath) } func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool { - return invokeAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true + return invoke(action: .shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true } } diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index e1ba1bc..9be3369 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -56,7 +56,7 @@ public class RowBuilder : NSObject { // MARK: internal methods, must be overriden in subclass - func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { + func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { return nil } @@ -67,7 +67,7 @@ public class RowBuilder : NSObject { /** Responsible for building cells of given type and passing items to them. */ -public class TableRowBuilder : RowBuilder { +public class TableBaseRowBuilder : RowBuilder { private var actions = [String: ActionHandler]() private var items = [DataType]() @@ -112,9 +112,9 @@ public class TableRowBuilder // MARK: Internal - override func invokeAction(type: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { + override func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { - if let action = actions[type.key] { + if let action = actions[action.key] { return action.invoke(ActionData(cell: cell as? CellType, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex, userInfo: userInfo)) } return nil @@ -153,7 +153,7 @@ public class TableRowBuilder /** Responsible for building configurable cells of given type and passing items to them. */ -public class TableConfigurableRowBuilder : TableRowBuilder { +public class TableRowBuilder : TableBaseRowBuilder { public override var estimatedRowHeight: Float { return CellType.estimatedHeight() @@ -167,21 +167,21 @@ public class TableConfigurableRowBuilder AnyObject? { + override func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { - switch actionType { + switch action { case .configure: (cell as? CellType)?.configure(items[itemIndex]) default: break } - return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex, userInfo: userInfo) + return super.invoke(action: action, cell: cell, indexPath: indexPath, itemIndex: itemIndex, userInfo: userInfo) } } -public func +=(left: TableRowBuilder, right: DataType) { +public func +=(left: TableBaseRowBuilder, right: DataType) { left.append(items: [right]) } -public func +=(left: TableRowBuilder, right: [DataType]) { +public func +=(left: TableBaseRowBuilder, right: [DataType]) { left.append(items: right) } \ No newline at end of file diff --git a/TabletDemo/Classes/Presentation/Controllers/HeaderFooterController.swift b/TabletDemo/Classes/Presentation/Controllers/HeaderFooterController.swift index 9666cca..1e1a7c7 100644 --- a/TabletDemo/Classes/Presentation/Controllers/HeaderFooterController.swift +++ b/TabletDemo/Classes/Presentation/Controllers/HeaderFooterController.swift @@ -21,7 +21,7 @@ class HeaderFooterController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - let rows = TableConfigurableRowBuilder(items: ["3", "4", "5"]) + let rows = TableRowBuilder(items: ["3", "4", "5"]) let headerView = UIView(frame: CGRectMake(0, 0, 100, 100)) headerView.backgroundColor = UIColor.lightGrayColor() diff --git a/TabletDemo/Classes/Presentation/Controllers/MainController.swift b/TabletDemo/Classes/Presentation/Controllers/MainController.swift index 2c1ad9e..11e982b 100644 --- a/TabletDemo/Classes/Presentation/Controllers/MainController.swift +++ b/TabletDemo/Classes/Presentation/Controllers/MainController.swift @@ -21,7 +21,7 @@ class MainController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - let rows = TableConfigurableRowBuilder(items: ["1", "2", "3"]) + let rows = TableRowBuilder(items: ["1", "2", "3"]) .action(.click) { [unowned self] e in self.performSegueWithIdentifier("headerfooter", sender: nil) } @@ -35,8 +35,6 @@ class MainController: UIViewController { } - - print("", String(TableDirector.self)) tableDirector += rows }