rowitem improvements
This commit is contained in:
parent
21f131bb19
commit
c27a386807
|
|
@ -23,6 +23,7 @@ import UIKit
|
|||
public protocol RowItemable {
|
||||
|
||||
var reusableIdentifier: String { get }
|
||||
var estimatedHeight: CGFloat { get }
|
||||
|
||||
func configure(cell: UITableViewCell)
|
||||
}
|
||||
|
|
@ -35,6 +36,10 @@ public class RowItem<DataType, CellType: ConfigurableCell where CellType.T == Da
|
|||
return CellType.reusableIdentifier()
|
||||
}
|
||||
|
||||
public var estimatedHeight: CGFloat {
|
||||
return CellType.estimatedHeight()
|
||||
}
|
||||
|
||||
public init(item: DataType) {
|
||||
self.item = item
|
||||
}
|
||||
|
|
@ -45,30 +50,21 @@ public class RowItem<DataType, CellType: ConfigurableCell where CellType.T == Da
|
|||
}
|
||||
|
||||
public class TableDynamicRowBuilder: RowBuilder {
|
||||
|
||||
var items = [RowItemable]()
|
||||
|
||||
public private(set) weak var tableDirector: TableDirector?
|
||||
private var items = [RowItemable]()
|
||||
|
||||
public init(items: [RowItemable]) {
|
||||
self.items = items
|
||||
|
||||
}
|
||||
|
||||
func configure(cell: UITableViewCell, itemIndex: Int) {
|
||||
|
||||
let cellItem = items[itemIndex]
|
||||
|
||||
cellItem.configure(cell)
|
||||
}
|
||||
|
||||
// MARK: - RowConfigurable -
|
||||
|
||||
public func configure(cell: UITableViewCell, path: NSIndexPath, index: Int) {
|
||||
|
||||
items[index].configure(cell)
|
||||
}
|
||||
|
||||
// MARK: - RowBuilder -
|
||||
|
||||
public private(set) weak var tableDirector: TableDirector?
|
||||
|
||||
public var numberOfRows: Int {
|
||||
return items.count
|
||||
|
|
@ -87,6 +83,11 @@ public class TableDynamicRowBuilder: RowBuilder {
|
|||
return nil
|
||||
}
|
||||
|
||||
public func action(handler: (item: RowItemable, path: NSIndexPath) -> Void) -> Self {
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// MARK: - RowHeightCalculatable -
|
||||
|
||||
public func rowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat {
|
||||
|
|
@ -94,6 +95,6 @@ public class TableDynamicRowBuilder: RowBuilder {
|
|||
}
|
||||
|
||||
public func estimatedRowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat {
|
||||
return 0 //CellType.estimatedHeight()
|
||||
return items[index].estimatedHeight
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,8 @@ class MainController: UIViewController {
|
|||
super.viewDidLoad()
|
||||
|
||||
let rowBuilder = TableRowBuilder<String, StoryboardImageTableViewCell>(items: ["1", "1", "1", "1"])
|
||||
.action(.click) { [unowned self] e in
|
||||
.action(.click) { [unowned self] data in
|
||||
|
||||
self.performSegueWithIdentifier("headerfooter", sender: nil)
|
||||
}
|
||||
|
||||
|
|
@ -34,13 +35,33 @@ class MainController: UIViewController {
|
|||
|
||||
|
||||
let cellItem = RowItem<String, StoryboardImageTableViewCell>(item: "1")
|
||||
let cellItem2 = RowItem<String, StoryboardImageTableViewCell>(item: "1")
|
||||
let cellItem3 = RowItem<String, StoryboardImageTableViewCell>(item: "1")
|
||||
let cellItem2 = RowItem<String, StoryboardImageTableViewCell>(item: "2")
|
||||
let cellItem3 = RowItem<String, StoryboardImageTableViewCell>(item: "3")
|
||||
|
||||
|
||||
|
||||
|
||||
let b = TableDynamicRowBuilder(items: [cellItem, cellItem2, cellItem3])
|
||||
.action { (item, path) in
|
||||
|
||||
if let x = item as? RowItem<String, StoryboardImageTableViewCell> {
|
||||
|
||||
}
|
||||
}
|
||||
.action { (item, path) in
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
tableDirector += b
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*rowBuilder
|
||||
|
|
@ -70,6 +91,6 @@ class MainController: UIViewController {
|
|||
//tableDirector.performBatchUpdates {
|
||||
//}*/
|
||||
|
||||
tableDirector.append(section: section)
|
||||
//tableDirector.append(section: section)
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ class StoryboardImageTableViewCell: UITableViewCell, ConfigurableCell {
|
|||
|
||||
func configure(string: T) {
|
||||
|
||||
titleLabel.text = "Test"
|
||||
titleLabel.text = string
|
||||
subtitleLabel.text = "Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.1"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue