user6092898
user6092898

Reputation:

Pulltorefresh works only once not multiple times

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

  1. attributedTitle is not visible
  2. The pull to refresh works only once and If i pull it again , it does not work. Why is that so?

Upvotes: 2

Views: 1089

Answers (2)

Arshad Shaik
Arshad Shaik

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

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

Related Questions