Reputation:
I have got a tableview with prototype cells.
I have got the following code in my viewDidLoad method,
_refreshControl = [[UIRefreshControl alloc]init];
[_refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = _tblView;
tableViewController.refreshControl = _refreshControl;
Following is my refreshData method....
-(void)refreshData
{
[_request getApproveStatutoryMapping];
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = _tblView;
[_tblView reloadData];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
forKey:NSForegroundColorAttributeName];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
tableViewController.refreshControl.attributedTitle = attributedTitle;
[tableViewController.refreshControl endRefreshing];
}
The problem is that
Upvotes: 2
Views: 1089
Reputation: 1274
I was getting the same problem, that the pull to refresh is working only once. After lot of struggle, i got a solution ie., before loading data into the tableview we need to stop pull to refresh.
refreshControl.endRefreshing()
I hope it might help.
Upvotes: 1
Reputation: 336
You will define UITableViewController *tableViewController
like a property of your UIViewController
In the method refreshData
delete lines
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = _tblView;
Method endRefreshing
must be invoked after your refresh data, not when you begin refresh it, or you will see pre-loader less than a second without waiting for the updates
Here
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
forKey:NSForegroundColorAttributeName];
You define color of your refresh title like white, if the background is white you will never see title
Upvotes: 0