Skip to content

Commit

Permalink
Add reload data, fixed reload data method
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 21, 2017
1 parent 1d59d07 commit d14d185
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion YNExpandableCell.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions YNExpandableCell/YNExpandableCell/YNTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
}
Expand All @@ -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 }
Expand Down

0 comments on commit d14d185

Please sign in to comment.