UITableView告别蛋疼的上拉更新,自动刷新数据。
来源:互联网 发布:淘宝pc转换无线连接 编辑:程序博客网 时间:2024/06/06 08:36
前语:上更新确实是个好东西,但是本人不喜欢。因为当我阅读完当前的数据的时候,还要上拉一下,等待刷新,这个对浏览信息来说是一个很蛋疼的事情。
下面介绍一下很简单的一个自动刷新的方法:(很简单的哦~!)
在delegate 里面
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
NSInteger row = [indexPathrow];
if (_userRequestDataNumber<self.optionNumber) { //首先判断是否还有可以刷新的数据
if (row==(numberOfCell-5)&&[_requestisFinished]) { //如果当用户滑动到倒数第五个的时候,而且当前请求已经结束的时候,去加载更多的数据。
[selfloadMoreData]; //获取更多数据方法、
}
}
}
当然要处理一下tableview最后一个cell的效果,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger count =self.bookTitleArray.count; //总的cell个数、
if (count ==0) {
return0;
}
if (_userRequestDataNumber <self.optionNumber) { //如果还有可刷新的数据、返回cell的个数是 多一个。(包含tableview最后的那个刷新cell).
return count +1;
}
return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPathrow];
if(row == _bookTitleArray.count) {
staticNSString *MoreCellIdentifier =@"TableMoreCell";
TableMoreCell *moreCell = [tableViewdequeueReusableCellWithIdentifier:MoreCellIdentifier];
if (!moreCell) {
NSArray *nib = [[NSBundlemainBundle]loadNibNamed:@"TableMoreCell"owner:selfoptions:nil];
moreCell = [nib objectAtIndex:0];
}
if (![_requestisFinished]) { //当前请求还没有结束的话显示小齿轮
/*-------加载小齿轮--------*./
moreCellActivityIndicatorView = [[UIActivityIndicatorViewalloc]initWithFrame:CGRectMake(70,12,20,20)];
moreCellActivityIndicatorView.activityIndicatorViewStyle =UIActivityIndicatorViewStyleGray;
moreCellActivityIndicatorView.hidesWhenStopped =YES;
[moreCellActivityIndicatorViewstartAnimating];
[moreCelladdSubview:moreCellActivityIndicatorView];
moreCell.stateLabel.text =@"正在加载";
}else{
moreCell.stateLabel.text =@"点击查看更多";
}
return moreCell;
} else {...........//正常cell的样式处理}
}效果图:如果滑动的慢,有刷新的数据,网速快的情况下,用户一直都不用手动去刷新,等到他还没有拉到最低端的时候,已经加载出了新的数据。
如果有人想等到用户拉到最低端在进行加载数据的话:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if(tableView.contentOffset.y + (tableView.frame.size.height) > tableView.contentSize.height){
//method
}
}
- UITableView告别蛋疼的上拉更新,自动刷新数据。
- ios:UITableView告别手动上拉更新,自动刷新数据
- UItableView的上拉与下拉刷新
- UITableView上拉下拉刷新
- UITableView之下拉刷新上拉加载
- UITableView 上拉刷新,下拉刷新
- UITableView之(九):上拉刷新的原理介绍
- UIScrollView UITableView 上拉刷新源码
- UITableView上拉与下拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView:下拉刷新和上拉加载
- uitableview上提刷新数据
- UITableView里的数据刷新和位置更新
- android自定义下拉刷新上拉更新的ListView
- ios中uitableview上拉刷新和下拉刷新(1)
- 动态IP或无公网IP时外网访问内网MYSQL数据库
- Arduino 串口通讯
- 可穿戴设备未来十大趋势
- lozi混沌映射吸引子,使用python的matplotlib绘制,可以放大和缩小
- 基于xmpp openfire smack开发之smack类库介绍和使用
- UITableView告别蛋疼的上拉更新,自动刷新数据。
- 基于xmpp openfire smack开发之Android客户端开发
- 创建型模式2:抽象工厂模式(Abstract Factory)
- 一次搞懂WCF 配置文件
- 基于xmpp openfire smack开发之Android消息推送技术原理分析和实践
- 基于xmpp openfire smack开发之openfire介绍和部署
- c++ 模拟浮点数运算
- rabbitmq初学之连接测试
- 格力与小米:谁将会赢