diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index a44748e..b79f730 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -185,7 +185,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate public func append(sections sections: [TableSectionBuilder]) { - sections.forEach { $0.willMoveToDirector(tableView) } + sections.forEach { $0.tableDirector = self } self.sections.appendContentsOf(sections) } diff --git a/Tablet/TableSectionBuilder.swift b/Tablet/TableSectionBuilder.swift index a011134..546ae0d 100644 --- a/Tablet/TableSectionBuilder.swift +++ b/Tablet/TableSectionBuilder.swift @@ -26,8 +26,14 @@ import Foundation Can host several row builders. */ public class TableSectionBuilder { + + weak var tableDirector: TableDirector? { + didSet { + guard let director = tableDirector else { return } + builders.forEach { $0.registerCell(inTableView: director.tableView) } + } + } - weak var tableView: UITableView? private var builders = [RowBuilder]() public var headerTitle: String? @@ -74,7 +80,7 @@ public class TableSectionBuilder { public func append(rows rows: [RowBuilder]) { - if let tableView = tableView { rows.forEach { $0.registerCell(inTableView: tableView) } } + if let tableView = tableDirector?.tableView { rows.forEach { $0.registerCell(inTableView: tableView) } } builders.appendContentsOf(rows) } @@ -92,12 +98,6 @@ public class TableSectionBuilder { return nil } - - func willMoveToDirector(tableView: UITableView) { - - self.tableView = tableView - self.builders.forEach { $0.registerCell(inTableView: tableView) } - } } public func +=(left: TableSectionBuilder, right: RowBuilder) {