I am trying to implement the pull to refresh functionality in my application. The architecture is such that the there is a UITableView
inside a UIViewController
. I want to be able to refresh the tableview on pull down. I tried the code below in the viewDidLoad
method, but it does not work. Can any one tell me where am I wrong in implementation?
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.tintColor = [UIColor grayColor];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self action:@selector(get_vrns) forControlEvents:UIControlEventValueChanged];
[self.vrnTable addSubview:refresh];
For Swift 3 and iOS backward compatibility
var refreshControl = UIRefreshControl()
let string = "Pull to refresh"
let attributedString = NSMutableAttributedString(string: string)
attributedString.addAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 16)),NSForegroundColorAttributeName:UIColor.white], range: NSRange.init(location: 0, length: string.characters.count))
self.refreshControl.attributedTitle = attributedString
self.refreshControl.tintColor = UIColor.white
self.refreshControl.addTarget(self,
action: #selector(self.pulledDownForRefresh),
for: .valueChanged)
if #available(iOS 10.0, *) {
self.accountSummaryTableView.refreshControl = refreshControl
} else {
self.accountSummaryTableView.addSubview(refreshControl)
}
func pulledDownForRefresh() {
//do some opertaion and then call
self.refreshControl.endRefreshing()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With