I want to implement Pull To Refresh to my UITableViewController
by using UIRefreshControl
. Here what i tried so far.
- (void)viewDidLoad
{
.....
////********* Pull to refresh ************/
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
refresh.tintColor = [UIColor magentaColor];
// [self.tableView addSubview:refresh];
// [self.refreshControl setEnabled:YES];
[refresh addTarget:self action:@selector(pullToRefresh:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
}
-(void)pullToRefresh:(UIRefreshControl *)refresh {
[refresh beginRefreshing];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing.."];
[self loadRecentActivities];
}
But when i pull the tableview neither activity indicator nor title is visible, however pullToRefresh
is called and table refreshed.My app supports iOS7.0+.
What i'm missing? Any help would be appreciated?
Edit: I'v tried with [self.refreshControl setEnabled:YES];
and [self.refreshControl setEnabled:YES];
as mentioned in my edited code, but still no luck.
This is how my tableview looks like when i pull it to refresh-
Final Solution: For table view background i was using
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
self.tableView.backgroundView = imageView;
Refresh indicator and title was hidden behind the self.tableView.backgroundView
instead use
[self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];
and it solves my problem. also many thanks to Balram Tiwari please see his answer if you still have problem.
Just add self.tableView.backgroundView.layer.zPosition -= 1;
under the initialisation code for refreshControl.
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