set estimatedHeight and defaultHeight as static properties

This commit is contained in:
Max Sokolov 2016-08-20 13:02:17 +03:00
parent f90db7de16
commit 7438856134
4 changed files with 25 additions and 19 deletions

View File

@ -19,13 +19,13 @@ class AutolayoutTableViewCell: UITableViewCell, ConfigurableCell {
@IBOutlet var titleLabel: UILabel!
@IBOutlet var subtitleLabel: UILabel!
static var estimatedHeight: CGFloat? {
return 500
}
func configure(with string: T) {
titleLabel.text = LoremIpsumTitle
subtitleLabel.text = LoremIpsumBody
}
static func estimatedHeight() -> CGFloat? {
return 500
}
}

View File

@ -13,11 +13,11 @@ class NibTableViewCell: UITableViewCell, ConfigurableCell {
@IBOutlet weak var titleLabel: UILabel!
static var defaultHeight: CGFloat? {
return 100
}
func configure(with number: Int) {
titleLabel.text = "\(number)"
}
static func defaultHeight() -> CGFloat? {
return 100
}
}

View File

@ -21,17 +21,18 @@
import UIKit
public protocol ReusableCell {
static func reusableIdentifier() -> String
static func nib() -> UINib?
}
public protocol ConfigurableCell: ReusableCell {
associatedtype T
static func estimatedHeight() -> CGFloat?
static func defaultHeight() -> CGFloat?
static var estimatedHeight: CGFloat? { get }
static var defaultHeight: CGFloat? { get }
func configure(with _: T)
}
@ -48,11 +49,16 @@ public extension ReusableCell where Self: UITableViewCell {
public extension ConfigurableCell where Self: UITableViewCell {
static func estimatedHeight() -> CGFloat? {
return UITableViewAutomaticDimension
static var estimatedHeight: CGFloat? {
get {
return UITableViewAutomaticDimension
}
}
static func defaultHeight() -> CGFloat? {
return nil
static var defaultHeight: CGFloat? {
get {
return nil
}
}
}

View File

@ -59,11 +59,11 @@ public class TableRow<ItemType, CellType: ConfigurableCell where CellType.T == I
}
public var estimatedHeight: CGFloat? {
return CellType.estimatedHeight()
return CellType.estimatedHeight
}
public var defaultHeight: CGFloat? {
return CellType.defaultHeight()
return CellType.defaultHeight
}
public var cellType: AnyClass {