From 6498e39daa77527c96d77788492538c0cb1cafdd Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Sun, 15 May 2016 15:09:27 +0300 Subject: [PATCH] sections now keep reference to director instead of table view --- Tablet/TableDirector.swift | 2 +- Tablet/TableSectionBuilder.swift | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) 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) {