I can't seem to find a working solution. I've tried the other available solutions to implement pull to refresh in a UITableView without a UITableViewController but nothing happens.
This is the relevant code:
@IBOutlet weak var tableView: UITableView!
var peopleRefreshControl:UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
peopleRefreshControl = UIRefreshControl()
peopleRefreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
peopleRefreshControl.addTarget(self, action: "refresh", forControlEvents: .ValueChanged)
// I also tried this
// peopleRefreshControl.addTarget(self, action: Selector("refresh"), forControlEvents: .ValueChanged)
tableView.addSubview(peopleRefreshControl)
}
func refresh(){
println("what!")
}
I can see the circle spinning and the text "Pull to refresh" when I pull down, but the function "refresh" is never called. What am I doing wrong? Is there something else that I should be doing? I'm not doing anything special with the tableView other than hiding it when it's not being used. Could that somehow be a problem?
Edit: I updated the code to include ":" as follows but there was absolutely no change. I still see the circle spinning and the text "Pull to refresh" but the text "what!" is never printed out.
override func viewDidLoad() {
super.viewDidLoad()
...
peopleRefreshControl.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)
...
}
func refresh(sender:UIRefreshControl){
println("what!")
}
Is there something else I should be doing?
Thats because you did not add a ":" after the word refresh in the viewDidLoad. Without it, the refresh function won't run. Try using this code...