Hi in my app I have a stretchy header and I am adding my refresh control like this tableView.addSubview(refreshControll)
But when using it, it is in middle or bottom of my view and not pinned to the top how do I fix this?
Hi in my app I have a stretchy header and I am adding my refresh control like this tableView.addSubview(refreshControll)
But when using it, it is in middle or bottom of my view and not pinned to the top how do I fix this?
Since iOS 10 or iOS 11 UITableView
and UICollectionView
have gotten their own refresh control option.
var refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(reloadData), for: UIControl.Event.valueChanged)
tableView.refreshControl = refreshControl
You can also look at the Apple documentation about UITableViewController
.
From iOS 10 you have two options to add a refresh control to a UIScrollView: You can add it to the tableView like another refresh control :
tableView.addSubview(refreshControl)
This will show the refreshControl on top of the UITableView, more precisely like if it was added to the tableHeaderView. The other option, is to use the already included refreshControl in the UIScrollView classes:
tableView.refreshControl = UIRefreshControl()
With this option the UIViewController takes control of where to put the refreshControl, since iOS 10 will move it to the top of the view just above the navigation bar. Check Mail app on the iPhone to see and example.
refreshControl.addTarget(self, action: #selector(refresh( sender:)), for: .valueChanged)
tableView.insertSubview(refreshControl, at: 0)
func refresh(sender: UIRefreshControl) {
sender.beginRefreshing()
// refresh tableview datasource
refresh()
}