Pull to Refresh UIViewController in iOS
If you try to add a UIRefreshControl to a UIViewController, you’ll get an error.
UIRefreshControl can only be managed by a
UITableViewController.
So, here’s a trick.
Code
- Set up a table view in your
UIViewController.
1 | let refreshControl = UIRefreshControl() |
- Add
refreshControltotableView, notview.
1 | tableView.frame = view.frame |
refreshViewfunction.
1 | func refreshView(refreshControl: UIRefreshControl) { |
If you, like me, prefer to use Storyboard
Storyboard -> UITableViewController -> enable Refreshing.
Then you can
Ctrl+ drag just likeUIButton.
Translated by gpt-3.5-turbo