Skip to content

Commit

Permalink
Merge pull request #57 from venmo/ma/fix-row-heights
Browse files Browse the repository at this point in the history
Support row heights set via `UITableView.rowHeight`
  • Loading branch information
lionel-alves committed Oct 23, 2015
2 parents e9eedb5 + dbc6bc3 commit 0645958
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ViewController: TableViewController {
super.viewDidLoad()

title = "Static"

tableView.rowHeight = 66

dataSource.sections = [
Section(header: "Styles", rows: [
Expand All @@ -36,8 +38,8 @@ class ViewController: TableViewController {
Row(text: "Button", detailText: "Detail", cellClass: ButtonCell.self, selection: { [unowned self] in
self.showAlert(title: "Row Selection")
}),
Row(text: "Custom cell with explicit height", cellClass: CustomTableViewCell.self, height: 64),
Row(text: "Custom from nib", cellClass: NibTableViewCell.self)
Row(text: "Custom cell with explicit height", cellClass: CustomTableViewCell.self, height: 44),
Row(text: "Custom from nib", cellClass: NibTableViewCell.self, height: UITableViewAutomaticDimension)
], footer: "This is a section footer."),
Section(header: "Accessories", rows: [
Row(text: "None"),
Expand Down
14 changes: 8 additions & 6 deletions Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,19 @@ extension DataSource: UITableViewDataSource {
}

public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return rowForIndexPath(indexPath)?.height ?? UITableViewAutomaticDimension
guard let height = rowForIndexPath(indexPath)?.height else {
return tableView.rowHeight
}

return height
}

public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
guard let row = rowForIndexPath(indexPath) else { return UITableViewAutomaticDimension }

if row.height == UITableViewAutomaticDimension {
return 44
guard let height = rowForIndexPath(indexPath)?.height else {
return UITableViewAutomaticDimension
}

return row.height
return height
}

public func numberOfSectionsInTableView(tableView: UITableView) -> Int {
Expand Down
6 changes: 3 additions & 3 deletions Static/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public struct Row: Hashable, Equatable {
/// View to be used for the row.
public var cellClass: CellType.Type

/// The row's height. Defaults to `UITableViewAutomaticDimension`.
public var height: CGFloat
/// The row's height.
public var height: CGFloat?

/// Additional information for the row.
public var context: Context?
Expand Down Expand Up @@ -140,7 +140,7 @@ public struct Row: Hashable, Equatable {
// MARK: - Initializers

public init(text: String? = nil, detailText: String? = nil, selection: Selection? = nil,
image: UIImage? = nil, imageTintColor: UIColor? = nil, accessory: Accessory = .None, cellClass: CellType.Type? = nil, height: CGFloat = UITableViewAutomaticDimension, context: Context? = nil, editActions: [EditAction] = [], UUID: String = NSUUID().UUIDString) {
image: UIImage? = nil, imageTintColor: UIColor? = nil, accessory: Accessory = .None, cellClass: CellType.Type? = nil, height: CGFloat? = nil, context: Context? = nil, editActions: [EditAction] = [], UUID: String = NSUUID().UUIDString) {

self.UUID = UUID
self.text = text
Expand Down

0 comments on commit 0645958

Please sign in to comment.