From 5d062e7afbc4fc086f98b162b6b3906e80c23b46 Mon Sep 17 00:00:00 2001 From: Alex K Date: Wed, 12 Jun 2019 11:34:53 +0300 Subject: [PATCH] sections example --- .../Base.lproj/Main.storyboard | 46 +++++++++++-------- .../MainTableViewController.swift | 33 +++++++++---- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/FoldingCell/FoldingCell-Demo/Base.lproj/Main.storyboard b/FoldingCell/FoldingCell-Demo/Base.lproj/Main.storyboard index d3146f6..0dc3db2 100644 --- a/FoldingCell/FoldingCell-Demo/Base.lproj/Main.storyboard +++ b/FoldingCell/FoldingCell-Demo/Base.lproj/Main.storyboard @@ -1,37 +1,26 @@ - + - + - - - OpenSans-Light - - - OpenSans - - - OpenSans-Semibold - - - + - + - + @@ -381,7 +370,7 @@ - + @@ -693,19 +682,38 @@ + - + + + + + + + + + + + + + + + + + + + - + diff --git a/FoldingCell/FoldingCell-Demo/MainTableViewController.swift b/FoldingCell/FoldingCell-Demo/MainTableViewController.swift index 6c6b6e1..710e4fa 100644 --- a/FoldingCell/FoldingCell-Demo/MainTableViewController.swift +++ b/FoldingCell/FoldingCell-Demo/MainTableViewController.swift @@ -30,19 +30,20 @@ class MainTableViewController: UITableViewController { static let closeCellHeight: CGFloat = 179 static let openCellHeight: CGFloat = 488 static let rowsCount = 10 + static let sectionCount = 5 } - var cellHeights: [CGFloat] = [] + private var cellHeights: [[CGFloat]] = (0.. Int { + return cellHeights.count + } - override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int { - return 10 + override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int { + return cellHeights[section].count + } + + override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let view = UIView() + view.backgroundColor = .red + return view + } + + override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return 44 } override func tableView(_: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { @@ -79,7 +94,7 @@ extension MainTableViewController { cell.backgroundColor = .clear - if cellHeights[indexPath.row] == Const.closeCellHeight { + if cellHeights[indexPath.section][indexPath.row] == Const.closeCellHeight { cell.unfold(false, animated: false, completion: nil) } else { cell.unfold(true, animated: false, completion: nil) @@ -97,7 +112,7 @@ extension MainTableViewController { } override func tableView(_: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return cellHeights[indexPath.row] + return cellHeights[indexPath.section][indexPath.row] } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -109,13 +124,13 @@ extension MainTableViewController { } var duration = 0.0 - let cellIsCollapsed = cellHeights[indexPath.row] == Const.closeCellHeight + let cellIsCollapsed = cellHeights[indexPath.section][indexPath.row] == Const.closeCellHeight if cellIsCollapsed { - cellHeights[indexPath.row] = Const.openCellHeight + cellHeights[indexPath.section][indexPath.row] = Const.openCellHeight cell.unfold(true, animated: true, completion: nil) duration = 0.5 } else { - cellHeights[indexPath.row] = Const.closeCellHeight + cellHeights[indexPath.section][indexPath.row] = Const.closeCellHeight cell.unfold(false, animated: true, completion: nil) duration = 0.8 }