Skip to content

Commit 9dfe11f

Browse files
committed
add refresh to HomeVC
1 parent 308ae0e commit 9dfe11f

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

AnimalsApp/AnimalsApp/Views/HomeViewController/HomeViewController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class HomeViewController: UIViewController {
2424
tableView.register(UINib(nibName: "AnimalTableViewCell", bundle: nil), forCellReuseIdentifier: "Animal")
2525

2626
setNavigationItems()
27+
28+
let refreshControl = UIRefreshControl()
29+
refreshControl.addTarget(self, action: #selector(reloadAnimals), for: .valueChanged)
30+
tableView.refreshControl = refreshControl
31+
}
32+
33+
override func viewWillAppear(_ animated: Bool) {
2734
populateTableView()
2835
}
2936

@@ -49,6 +56,12 @@ class HomeViewController: UIViewController {
4956
}
5057
}
5158
}
59+
60+
@objc
61+
private func reloadAnimals(refreshControl: UIRefreshControl) {
62+
populateTableView()
63+
refreshControl.endRefreshing()
64+
}
5265
}
5366

5467
extension HomeViewController: UITableViewDataSource {

0 commit comments

Comments
 (0)