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
refreshControl
totableView
, notview
.
1 | tableView.frame = view.frame |
refreshView
function.
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