Fer*_*lva 5 iphone uitableview
许多iPhone项目使用"Pull-to-Refresh"模式来加载更多结果(通常是来自服务器的新数据).
在我的项目中,我想做的恰恰相反:"拉起来刷新".我想从服务器加载旧数据,但我需要用户请求提取UITableView的数据.
我该怎么做?有谁能够帮我?
这是我一直在使用的:
首先,您有一个视图,其中包含"拉起刷新消息",并将其分配给:
[pullUpView setFrame:CGRectMake(0, [tableView rectForFooterInSection:0].origin.y, [tableView bounds].size.width,pullUpView.frame.height)];
Run Code Online (Sandbox Code Playgroud)
然后设置两个委托方法,如下所示,以跟踪拖动.
- (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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后还原tableView的contentInset以隐藏pullUpView.
| 归档时间: |
|
| 查看次数: |
7203 次 |
| 最近记录: |