Many iPhone projects use "Pull-to-Refresh" pattern to load more results (usually new data from the server.
In my project I want to do just the opposite: "pull-up to refresh". I want to load old data from the server but I need that the user request the data pulling up the UITableView.
How can I do it? Can anybody help me?
Here's what I've been using:
First of all you have a view holding the "Pull up to refresh message", and assign it to:
[pullUpView setFrame:CGRectMake(0, [tableView rectForFooterInSection:0].origin.y, [tableView bounds].size.width,pullUpView.frame.height)];
Then you setup two delegate methods as below to track the dragging.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.isDragging) {
CGFloat thresholdToRelease = [pullUpView frame].origin.y - [scrollView bounds].size.height;
CGFloat thresholdToLoad = thresholdToRelease + [pullUpView frame].size.height;
if (([scrollView contentOffset].y >= thresholdToRelease) && ([scrollView contentOffset].y < thresholdToLoad)) {
[pullUpView reset];
} else if ([scrollView contentOffset].y >= thresholdToLoad) {
[pullUpView indicateThresholdRearched];
}
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
CGFloat thresholdToAction = [pullUpView frame].origin.y + [pullUpView frame].size.height - [scrollView bounds].size.height;
if ([scrollView contentOffset].y >= thresholdToAction) {
if (!performingAction) {
[pullUpView startLoading];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[tableView setContentInset:UIEdgeInsetsMake(0, 0, [pullUpView frame].size.height, 0)];
[UIView commitAnimations];
/* do your things here */
performingAction = YES;
}
}
}
At the end revert the tableView's contentInset to hide the pullUpView.
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