From d14d18545084a1650b4bcea2f5fb8cd44420af07 Mon Sep 17 00:00:00 2001 From: "younatics@gmail.com" <1darklose> Date: Tue, 21 Mar 2017 23:36:45 +0900 Subject: [PATCH] Add reload data, fixed reload data method --- CHANGELOG.md | 4 ++++ YNExpandableCell.podspec | 2 +- .../YNExpandableCell/YNTableView.swift | 23 +++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a39d693..eaaf3f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Updates +## [v0.6.0](https://github.com/younatics/YNExpandableCell/releases/tag/0.6.0) +* Add override tableview `reloadData` method +* Fix bug + ## [v0.5.1](https://github.com/younatics/YNExpandableCell/releases/tag/0.5.1) * Update Readme diff --git a/YNExpandableCell.podspec b/YNExpandableCell.podspec index 3b9ac0c..3be250c 100644 --- a/YNExpandableCell.podspec +++ b/YNExpandableCell.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'YNExpandableCell' - s.version = '0.5.1' + s.version = '0.6.0' s.summary = 'Easiest way to expand and collapse cell for iOS with Swift 3' s.description = <<-DESC diff --git a/YNExpandableCell/YNExpandableCell/YNTableView.swift b/YNExpandableCell/YNExpandableCell/YNTableView.swift index af2ba94..9455c9e 100644 --- a/YNExpandableCell/YNExpandableCell/YNTableView.swift +++ b/YNExpandableCell/YNExpandableCell/YNTableView.swift @@ -85,6 +85,14 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate //PRAGMA MARK: YNTableView Delegate + /// Overide tableview reloadData + open override func reloadData() { + super.reloadData() + for expandedIndexPath in expandedIndexPaths { + let internalIndexPath = IndexPath(row: expandedIndexPath.row-1, section: expandedIndexPath.section) + self.selectRow(at: internalIndexPath, animated: true, scrollPosition: .none) + } + } /// Basic UITableViewDelegate: func numberOfSections(in tableView: UITableView) -> Int open func numberOfSections(in tableView: UITableView) -> Int { guard let delegate = self.ynDelegate else { return Int() } @@ -123,21 +131,24 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate return delegate.tableView(self, cellForRowAt: internalIndexPath) } + /// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { guard let delegate = self.ynDelegate else { return } + var didSelectRowAtSended = false + let selectedIndexPath = IndexPath(row: indexPath.row - self.expandedRowCountSince(current: indexPath), section: indexPath.section) if (delegate.tableView(self, expandCellAt: selectedIndexPath)) != nil { delegate.tableView(self, didSelectRowAt: indexPath, isExpandedCell: true) - + + didSelectRowAtSended = true var sameIndexPathExists = false for expandedIndexPath in self.expandedIndexPaths { if indexPath == expandedIndexPath { sameIndexPathExists = true } } - if !sameIndexPathExists { self.didSelectRowLogicAt(indexPath: indexPath) } @@ -146,6 +157,10 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate self.didSelectRowLogicAt(indexPath: indexPath) } } else { + delegate.tableView(self, didSelectRowAt: indexPath, isExpandedCell: true) + didSelectRowAtSended = true + } + if !didSelectRowAtSended { delegate.tableView(self, didSelectRowAt: indexPath, isExpandedCell: false) } } @@ -157,6 +172,10 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate for expandedIndexPath in self.expandedIndexPaths { let internalIndexPath = IndexPath(row: expandedIndexPath.row - 1, section: expandedIndexPath.section) + if expandedIndexPath == indexPath { + delegate.tableView(self, didDeselectRowAt: indexPath, isExpandedCell: true) + return + } if internalIndexPath == indexPath { let index = self.expandedIndexPaths.index(of: expandedIndexPath) guard let _index = index else { return }