Skip to content

Commit

Permalink
Merge pull request #6 from manGoweb/load-existing-data-when-binding-t…
Browse files Browse the repository at this point in the history
…ableview

Fix memory leak and make sure table view data source and delegate are set before reloading tableview binding data
  • Loading branch information
rafiki270 authored Jun 28, 2019
2 parents b7be8db + 98c1057 commit 662b07e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Presentables/Classes/Table views/Presentables+UITableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ extension UITableView: PresentableCollectionElement {
if Thread.isMainThread {
reloadData()
} else {
DispatchQueue.main.async {
self.reloadData()
DispatchQueue.main.async { [weak self] in
self?.reloadData()
}
}
}

public func bind(withPresentableManager manager: inout PresentableManager) {
dataSource = manager as? UITableViewDataSource
delegate = manager as? UITableViewDelegate

let m = manager
manager.bindableData.bind { [weak m] (data) in
if let data = m?.data {
Expand All @@ -47,10 +50,7 @@ extension UITableView: PresentableCollectionElement {
manager.needsReloadData = {
self.safeReloadData()
}

dataSource = manager as? UITableViewDataSource
delegate = manager as? UITableViewDelegate


if let manager = manager as? PresentableTableViewDataManager {
manager.tableView = self
}
Expand Down

0 comments on commit 662b07e

Please sign in to comment.