Skip to content

Commit 7e34a65

Browse files
committed
Update usage recommendations (closes #26)
1 parent 5c12b17 commit 7e34a65

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

PullToRefreshDemo/ViewController.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ class ViewController: UIViewController {
1616
@IBOutlet private var tableView: UITableView!
1717
private var dataSourceCount = PageSize
1818

19-
override func viewDidAppear(animated: Bool) {
20-
super.viewDidAppear(animated)
21-
19+
override func viewDidLoad() {
20+
super.viewDidLoad()
21+
2222
setupPullToRefresh()
2323
}
2424

25-
override func viewDidDisappear(animated: Bool) {
26-
super.viewDidDisappear(animated)
27-
25+
deinit {
2826
tableView.removePullToRefresh(tableView.bottomPullToRefresh!)
2927
tableView.removePullToRefresh(tableView.topPullToRefresh!)
3028
}
@@ -37,26 +35,20 @@ class ViewController: UIViewController {
3735
private extension ViewController {
3836

3937
func setupPullToRefresh () {
40-
41-
4238
tableView.addPullToRefresh(PullToRefresh()) { [weak self] in
4339
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
4440
dispatch_after(delayTime, dispatch_get_main_queue()) {
45-
dispatch_async(dispatch_get_main_queue()) {
46-
self?.dataSourceCount = PageSize
47-
self?.tableView.endRefreshing(at: .Top)
48-
}
41+
self?.dataSourceCount = PageSize
42+
self?.tableView.endRefreshing(at: .Top)
4943
}
5044
}
51-
45+
5246
tableView.addPullToRefresh(PullToRefresh(position: .Bottom)) { [weak self] in
5347
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
5448
dispatch_after(delayTime, dispatch_get_main_queue()) {
55-
dispatch_async(dispatch_get_main_queue()) {
5649
self?.dataSourceCount += PageSize
5750
self?.tableView.reloadData()
5851
self?.tableView.endRefreshing(at: .Bottom)
59-
}
6052
}
6153
}
6254
}
@@ -73,4 +65,4 @@ extension ViewController:UITableViewDataSource {
7365
cell.textLabel?.text = "\(indexPath.row)"
7466
return cell
7567
}
76-
}
68+
}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ tableView.addPullToRefresh(refresher, action: {
3838
})
3939
```
4040

41+
⚠️ Don't forget to remove pull to refresh when your view controller is releasing. ⚠️
42+
43+
```swift
44+
deinit {
45+
tableView.removePullToRefresh(tableView.topPullToRefresh!)
46+
}
47+
```
48+
49+
4150
After the action is completed and you want to hide the refresher:
4251

4352
```swift

0 commit comments

Comments
 (0)