method names refactoring
This commit is contained in:
parent
7083462aca
commit
c3fda15cb4
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<DataType, CellType where CellType: UITableViewCell> : RowBuilder {
|
||||
public class TableBaseRowBuilder<DataType, CellType where CellType: UITableViewCell> : RowBuilder {
|
||||
|
||||
private var actions = [String: ActionHandler<DataType, CellType>]()
|
||||
private var items = [DataType]()
|
||||
|
|
@ -112,9 +112,9 @@ public class TableRowBuilder<DataType, CellType where CellType: UITableViewCell>
|
|||
|
||||
// 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<DataType, CellType where CellType: UITableViewCell>
|
|||
/**
|
||||
Responsible for building configurable cells of given type and passing items to them.
|
||||
*/
|
||||
public class TableConfigurableRowBuilder<DataType, CellType: ConfigurableCell where CellType.T == DataType, CellType: UITableViewCell> : TableRowBuilder<DataType, CellType> {
|
||||
public class TableRowBuilder<DataType, CellType: ConfigurableCell where CellType.T == DataType, CellType: UITableViewCell> : TableBaseRowBuilder<DataType, CellType> {
|
||||
|
||||
public override var estimatedRowHeight: Float {
|
||||
return CellType.estimatedHeight()
|
||||
|
|
@ -167,21 +167,21 @@ public class TableConfigurableRowBuilder<DataType, CellType: ConfigurableCell wh
|
|||
super.init(items: items, id: CellType.reusableIdentifier())
|
||||
}
|
||||
|
||||
override func invokeAction(actionType: 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? {
|
||||
|
||||
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 +=<DataType, CellType>(left: TableRowBuilder<DataType, CellType>, right: DataType) {
|
||||
public func +=<DataType, CellType>(left: TableBaseRowBuilder<DataType, CellType>, right: DataType) {
|
||||
left.append(items: [right])
|
||||
}
|
||||
|
||||
public func +=<DataType, CellType>(left: TableRowBuilder<DataType, CellType>, right: [DataType]) {
|
||||
public func +=<DataType, CellType>(left: TableBaseRowBuilder<DataType, CellType>, right: [DataType]) {
|
||||
left.append(items: right)
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ class HeaderFooterController: UIViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
let rows = TableConfigurableRowBuilder<String, StoryboardTableViewCell>(items: ["3", "4", "5"])
|
||||
let rows = TableRowBuilder<String, StoryboardTableViewCell>(items: ["3", "4", "5"])
|
||||
|
||||
let headerView = UIView(frame: CGRectMake(0, 0, 100, 100))
|
||||
headerView.backgroundColor = UIColor.lightGrayColor()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class MainController: UIViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
let rows = TableConfigurableRowBuilder<String, StoryboardTableViewCell>(items: ["1", "2", "3"])
|
||||
let rows = TableRowBuilder<String, StoryboardTableViewCell>(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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue