diff --git a/Demo/Classes/Application/AppDelegate.swift b/Demo/Classes/Application/AppDelegate.swift index 69cc0e6..6f0117a 100644 --- a/Demo/Classes/Application/AppDelegate.swift +++ b/Demo/Classes/Application/AppDelegate.swift @@ -1,15 +1,7 @@ -// -// AppDelegate.swift -// TabletDemo -// -// Created by Max Sokolov on 08/11/15. -// Copyright © 2015 Tablet. All rights reserved. -// - import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? -} \ No newline at end of file +} diff --git a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift index 4ad780d..73c99ca 100644 --- a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift @@ -1,11 +1,3 @@ -// -// AutolayoutCellsController.swift -// TableKitDemo -// -// Created by Max Sokolov on 18/06/16. -// Copyright © 2016 Tablet. All rights reserved. -// - import UIKit import TableKit diff --git a/Demo/Classes/Presentation/Controllers/MainController.swift b/Demo/Classes/Presentation/Controllers/MainController.swift index 50a244a..ea59e42 100644 --- a/Demo/Classes/Presentation/Controllers/MainController.swift +++ b/Demo/Classes/Presentation/Controllers/MainController.swift @@ -1,11 +1,3 @@ -// -// MainController.swift -// TabletDemo -// -// Created by Max Sokolov on 16/04/16. -// Copyright © 2016 Tablet. All rights reserved. -// - import UIKit import TableKit diff --git a/Demo/Classes/Presentation/Controllers/NibCellsController.swift b/Demo/Classes/Presentation/Controllers/NibCellsController.swift index 544a095..1dccf26 100644 --- a/Demo/Classes/Presentation/Controllers/NibCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/NibCellsController.swift @@ -1,11 +1,3 @@ -// -// NibCellsController.swift -// TableKitDemo -// -// Created by Max Sokolov on 18/06/16. -// Copyright © 2016 Tablet. All rights reserved. -// - import UIKit import TableKit diff --git a/Demo/Classes/Presentation/Views/AutolayoutSectionHeaderView.swift b/Demo/Classes/Presentation/Views/AutolayoutSectionHeaderView.swift index db3f876..46d3a28 100644 --- a/Demo/Classes/Presentation/Views/AutolayoutSectionHeaderView.swift +++ b/Demo/Classes/Presentation/Views/AutolayoutSectionHeaderView.swift @@ -1,11 +1,3 @@ -// -// AutolayoutSectionHeaderView.swift -// TableKitDemo -// -// Created by Max on 13/12/2017. -// Copyright © 2017 Tablet. All rights reserved. -// - import UIKit final class AutolayoutSectionHeaderView: UIView { diff --git a/Demo/Classes/Presentation/Views/AutolayoutTableViewCell.swift b/Demo/Classes/Presentation/Views/AutolayoutTableViewCell.swift index 489b590..6126451 100644 --- a/Demo/Classes/Presentation/Views/AutolayoutTableViewCell.swift +++ b/Demo/Classes/Presentation/Views/AutolayoutTableViewCell.swift @@ -1,11 +1,3 @@ -// -// AutolayoutTableViewCell.swift -// TabletDemo -// -// Created by Max Sokolov on 24/05/16. -// Copyright © 2016 Tablet. All rights reserved. -// - import UIKit import TableKit diff --git a/Demo/Classes/Presentation/Views/ConfigurableTableViewCell.swift b/Demo/Classes/Presentation/Views/ConfigurableTableViewCell.swift index d685fc3..2aa714a 100644 --- a/Demo/Classes/Presentation/Views/ConfigurableTableViewCell.swift +++ b/Demo/Classes/Presentation/Views/ConfigurableTableViewCell.swift @@ -1,11 +1,3 @@ -// -// ConfigurableTableViewCell.swift -// TableKitDemo -// -// Created by Max Sokolov on 18/06/16. -// Copyright © 2016 Tablet. All rights reserved. -// - import UIKit import TableKit diff --git a/Demo/Classes/Presentation/Views/NibTableViewCell.swift b/Demo/Classes/Presentation/Views/NibTableViewCell.swift index d561314..8cf1d09 100644 --- a/Demo/Classes/Presentation/Views/NibTableViewCell.swift +++ b/Demo/Classes/Presentation/Views/NibTableViewCell.swift @@ -1,11 +1,3 @@ -// -// NibTableViewCell.swift -// TableKitDemo -// -// Created by Max Sokolov on 18/06/16. -// Copyright © 2016 Tablet. All rights reserved. -// - import UIKit import TableKit @@ -20,4 +12,4 @@ class NibTableViewCell: UITableViewCell, ConfigurableCell { func configure(with number: Int) { titleLabel.text = "\(number)" } -} \ No newline at end of file +} diff --git a/Sources/TableCellRegisterer.swift b/Sources/TableCellRegisterer.swift index 17928b8..a31ad01 100644 --- a/Sources/TableCellRegisterer.swift +++ b/Sources/TableCellRegisterer.swift @@ -48,7 +48,7 @@ class TableCellRegisterer { // in that case we could register nib if let _ = bundle.path(forResource: reuseIdentifier, ofType: "nib") { tableView?.register(UINib(nibName: reuseIdentifier, bundle: bundle), forCellReuseIdentifier: reuseIdentifier) - // otherwise, register cell class + // otherwise, register cell class } else { tableView?.register(cellType, forCellReuseIdentifier: reuseIdentifier) } diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index ea20fd1..a92f3db 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -48,7 +48,12 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return sections.isEmpty } - public init(tableView: UITableView, scrollDelegate: UIScrollViewDelegate? = nil, shouldUseAutomaticCellRegistration: Bool = true, cellHeightCalculator: RowHeightCalculator?) { + public init( + tableView: UITableView, + scrollDelegate: UIScrollViewDelegate? = nil, + shouldUseAutomaticCellRegistration: Bool = true, + cellHeightCalculator: RowHeightCalculator?) + { super.init() if shouldUseAutomaticCellRegistration { @@ -64,11 +69,22 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { NotificationCenter.default.addObserver(self, selector: #selector(didReceiveAction), name: NSNotification.Name(rawValue: TableKitNotifications.CellAction), object: nil) } - public convenience init(tableView: UITableView, scrollDelegate: UIScrollViewDelegate? = nil, shouldUseAutomaticCellRegistration: Bool = true, shouldUsePrototypeCellHeightCalculation: Bool = false) { - - let heightCalculator: TablePrototypeCellHeightCalculator? = shouldUsePrototypeCellHeightCalculation ? TablePrototypeCellHeightCalculator(tableView: tableView) : nil + public convenience init( + tableView: UITableView, + scrollDelegate: UIScrollViewDelegate? = nil, + shouldUseAutomaticCellRegistration: Bool = true, + shouldUsePrototypeCellHeightCalculation: Bool = false) + { + let heightCalculator: TablePrototypeCellHeightCalculator? = shouldUsePrototypeCellHeightCalculation + ? TablePrototypeCellHeightCalculator(tableView: tableView) + : nil - self.init(tableView: tableView, scrollDelegate: scrollDelegate, shouldUseAutomaticCellRegistration: shouldUseAutomaticCellRegistration, cellHeightCalculator: heightCalculator) + self.init( + tableView: tableView, + scrollDelegate: scrollDelegate, + shouldUseAutomaticCellRegistration: shouldUseAutomaticCellRegistration, + cellHeightCalculator: heightCalculator + ) } deinit { @@ -80,10 +96,18 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } // MARK: Public - @discardableResult - open func invoke(action: TableRowActionType, cell: UITableViewCell?, indexPath: IndexPath, userInfo: [AnyHashable: Any]? = nil) -> Any? { - return sections[indexPath.section].rows[indexPath.row].invoke(action: action, cell: cell, path: indexPath, userInfo: userInfo) + open func invoke( + action: TableRowActionType, + cell: UITableViewCell?, indexPath: IndexPath, + userInfo: [AnyHashable: Any]? = nil) -> Any? + { + return sections[indexPath.section].rows[indexPath.row].invoke( + action: action, + cell: cell, + path: indexPath, + userInfo: userInfo + ) } open override func responds(to selector: Selector) -> Bool { @@ -91,11 +115,12 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } open override func forwardingTarget(for selector: Selector) -> Any? { - return scrollDelegate?.responds(to: selector) == true ? scrollDelegate : super.forwardingTarget(for: selector) + return scrollDelegate?.responds(to: selector) == true + ? scrollDelegate + : super.forwardingTarget(for: selector) } // MARK: - Internal - func hasAction(_ action: TableRowActionType, atIndexPath indexPath: IndexPath) -> Bool { return sections[indexPath.section].rows[indexPath.row].has(action: action) } @@ -108,7 +133,6 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } // MARK: - Height - open func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { let row = sections[indexPath.section].rows[indexPath.row] @@ -117,7 +141,10 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { cellRegisterer?.register(cellType: row.cellType, forCellReuseIdentifier: row.reuseIdentifier) } - return row.defaultHeight ?? row.estimatedHeight ?? rowHeightCalculator?.estimatedHeight(forRow: row, at: indexPath) ?? UITableViewAutomaticDimension + return row.defaultHeight + ?? row.estimatedHeight + ?? rowHeightCalculator?.estimatedHeight(forRow: row, at: indexPath) + ?? UITableViewAutomaticDimension } open func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { @@ -130,11 +157,13 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { let rowHeight = invoke(action: .height, cell: nil, indexPath: indexPath) as? CGFloat - return rowHeight ?? row.defaultHeight ?? rowHeightCalculator?.height(forRow: row, at: indexPath) ?? UITableViewAutomaticDimension + return rowHeight + ?? row.defaultHeight + ?? rowHeightCalculator?.height(forRow: row, at: indexPath) + ?? UITableViewAutomaticDimension } // MARK: UITableViewDataSource - configuration - open func numberOfSections(in tableView: UITableView) -> Int { return sections.count } @@ -163,7 +192,6 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } // MARK: UITableViewDataSource - section setup - open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sections[section].headerTitle } @@ -173,7 +201,6 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } // MARK: UITableViewDelegate - section setup - open func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { return sections[section].headerView } @@ -191,11 +218,12 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { open func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { let section = sections[section] - return section.footerHeight ?? section.footerView?.frame.size.height ?? UITableViewAutomaticDimension + return section.footerHeight + ?? section.footerView?.frame.size.height + ?? UITableViewAutomaticDimension } // MARK: UITableViewDataSource - Index - public func sectionIndexTitles(for tableView: UITableView) -> [String]? { var indexTitles = [String]() @@ -216,12 +244,15 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return nil } - public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { + public func tableView( + _ tableView: UITableView, + sectionForSectionIndexTitle title: String, + at index: Int) -> Int + { return sectionsIndexTitlesIndexes?[index] ?? 0 } // MARK: UITableViewDelegate - actions - open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) @@ -258,7 +289,6 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } // MARK: - Row editing - open func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return sections[indexPath.section].rows[indexPath.row].isEditingAllowed(forIndexPath: indexPath) } @@ -341,7 +371,6 @@ extension TableDirector { } // MARK: - deprecated methods - @available(*, deprecated, message: "Use 'delete(sectionAt:)' method instead") @discardableResult open func delete(index: Int) -> Self { diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 96a2e48..780f680 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -38,7 +38,12 @@ public protocol RowActionable { var editingActions: [UITableViewRowAction]? { get } func isEditingAllowed(forIndexPath indexPath: IndexPath) -> Bool - func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? + func invoke( + action: TableRowActionType, + cell: UITableViewCell?, + path: IndexPath, + userInfo: [AnyHashable: Any]?) -> Any? + func has(action: TableRowActionType) -> Bool }