Skip to content

Commit

Permalink
Update usage recommendations (closes #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
serejahh committed Aug 1, 2016
1 parent 5c12b17 commit 7e34a65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
24 changes: 8 additions & 16 deletions PullToRefreshDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ class ViewController: UIViewController {
@IBOutlet private var tableView: UITableView!
private var dataSourceCount = PageSize

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

override func viewDidLoad() {
super.viewDidLoad()
setupPullToRefresh()
}

override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)

deinit {
tableView.removePullToRefresh(tableView.bottomPullToRefresh!)
tableView.removePullToRefresh(tableView.topPullToRefresh!)
}
Expand All @@ -37,26 +35,20 @@ class ViewController: UIViewController {
private extension ViewController {

func setupPullToRefresh () {


tableView.addPullToRefresh(PullToRefresh()) { [weak self] in
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
dispatch_async(dispatch_get_main_queue()) {
self?.dataSourceCount = PageSize
self?.tableView.endRefreshing(at: .Top)
}
self?.dataSourceCount = PageSize
self?.tableView.endRefreshing(at: .Top)
}
}

tableView.addPullToRefresh(PullToRefresh(position: .Bottom)) { [weak self] in
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
dispatch_async(dispatch_get_main_queue()) {
self?.dataSourceCount += PageSize
self?.tableView.reloadData()
self?.tableView.endRefreshing(at: .Bottom)
}
}
}
}
Expand All @@ -73,4 +65,4 @@ extension ViewController:UITableViewDataSource {
cell.textLabel?.text = "\(indexPath.row)"
return cell
}
}
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ tableView.addPullToRefresh(refresher, action: {
})
```

⚠️ Don't forget to remove pull to refresh when your view controller is releasing. ⚠️

```swift
deinit {
tableView.removePullToRefresh(tableView.topPullToRefresh!)
}
```


After the action is completed and you want to hide the refresher:

```swift
Expand Down

0 comments on commit 7e34a65

Please sign in to comment.