Search code examples
iosuitableviewuirefreshcontrol

UIRefreshControl not working inside Container View


I've got ViewController, that has ContainerView with another ViewController and UITableView.

I am adding UIRefreshControl to tableView (inside Container) like this:

refreshControl.addTarget(self, action: #selector(SomeViewController.reloadData), for: .valueChanged)
tableView.addSubview(refreshControl)

And it does not work. SomeViewController.reloadData is never called. Now when I do the same thing, except without container, everything works.

Should I set some delegates or something to main/top ViewController, that has Container?


Solution

  • Have you tried setting the refreshControl to the corresponding property on your tableView instead of adding it as a subview?

    tableView.refreshControl = refreshControl

    That should do it.

    edit: If you support any iOS earlier than 10, you will not be able to add it to the tableView directly but will instead need to add it to your UITableViewController, assuming you are using one.

    self.refreshControl = refreshControl