I have UITableview
像第一个这样的分页将从服务器获取 20 个对象并填充UITableView
然后,当它到达最后一行时,需要进行另一个服务调用来获取接下来的 20 个对象。
我的问题是我需要在表格底部添加活动指示器,并且应该显示“正在加载”,用户可以向上滚动以查看当前对象,但不应向下滚动。
有没有自定义控件?
有没有最好的方法来实现它?
提前致谢。
让我们尝试使用 TableView 页脚视图来显示活动指示器。
例如 :
Declare UIView * footerView;
在.h文件中
在.m文件中添加以下方法
- (void)viewDidLoad
{
[super viewDidLoad];
[self initFooterView];
}
-(void)initFooterView
{
footerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 40.0)];
UIActivityIndicatorView * actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
actInd.tag = 10;
actInd.frame = CGRectMake(150.0, 5.0, 20.0, 20.0);
actInd.hidesWhenStopped = YES;
[footerView addSubview:actInd];
actInd = nil;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
BOOL endOfTable = (scrollView.contentOffset.y >= ((self.contentArray.count * 40) - scrollView.frame.size.height)); // Here 40 is row height
if (self.hasMoreData && endOfTable && !self.isLoading && !scrollView.dragging && !scrollView.decelerating)
{
self.tableView.tableFooterView = footerView;
[(UIActivityIndicatorView *)[footerView viewWithTag:10] startAnimating];
}
}
Thanks!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)