UIRefreshControl not firing target after switching tab

I have navigation bar controller and inside one of the tab table view controller with pull down refresh action to refresh data from server.


When I start app and load view first time it works ok, but if I switch tab and come back action method isn't fired again, only spinner is spinning.


Here is some of the code used in my class that is extending UITableViewController:


//this is as class property:

let refresh = UIRefreshControl()


//inside viewDidLoad()

refresh.addTarget(self, action: #selector(reload), for: .valueChanged)

self.refreshControl = refresh

//and to manually fire reload action:

self.refreshControl?.beginRefreshing()

reload()


//inside viewWillAppear()

refresh.addTarget(self, action: #selector(reload), for: .valueChanged)

self.refreshControl = refresh

//these two lines have no effect whatsoever, even if I remove them nothing changes...


//and reload method:

@objc func reload()

{

print("reload")

fetchData()

}


reload() doesn't get called after switching tabs so user cannot manually reload data from server anymore.

Answered by matej@Ineor in 335939022
Accepted Answer

You don't tell how you initiate UIRefreshControl and how the class is defined.

But it is possible that it is empty after

let refresh = UIRefreshControl()

What is beginRefreshing doing ?


So, please, dont extract a few lines of code out of context. It is very difficult to help with a more comprehensive understanding of what you have defined. And no time to try and guess what it could be !

UIRefreshControl not firing target after switching tab
 
 
Q