列表下拉/上拉刷新:(三)强制刷新

列表下拉/上拉刷新:(三)强制刷新

分类: iPhone开发 2358人阅读 评论(3) 收藏 举报

一进入列表界面总不能是空的,这时候就要异步获取数据,也就是进行第一次刷新。因此要在这个并没有下拉拖动的时候就强制显示刷新header。

在基类中增加强制刷新接口:

  1. // force to refresh   
  2. -(void)showRefreshHeader:(BOOL)animated;  
// force to refresh
-(void)showRefreshHeader:(BOOL)animated;

实现:

  1. -(void)showRefreshHeader:(BOOL)animated{  
  2.     if (animated)  
  3.     {  
  4.         [UIView beginAnimations:nil context:NULL];  
  5.         [UIView setAnimationDuration:0.2];  
  6.         self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);// set the Inset   
  7.         // scroll the table view to the new top region   
  8.         [self.tableView scrollRectToVisible:CGRectMake(0, 0.0f, 1, 1) animated:NO];   
  9.         [UIView commitAnimations];  
  10.     }  
  11.     else  
  12.     {  
  13.         self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);  
  14.         [self.tableView scrollRectToVisible:CGRectMake(0, 0.0f, 1, 1) animated:NO];  
  15.     }  
  16.     if (_refreshHeaderView) {  
  17.         [_refreshHeaderView showRefreshingHeader:YES];  
  18.     }  
  19.   
  20. }  
-(void)showRefreshHeader:(BOOL)animated{
	if (animated)
	{
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationDuration:0.2];
		self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);// set the Inset
        // scroll the table view to the new top region
        [self.tableView scrollRectToVisible:CGRectMake(0, 0.0f, 1, 1) animated:NO];	
        [UIView commitAnimations];
	}
	else
	{
		self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
		[self.tableView scrollRectToVisible:CGRectMake(0, 0.0f, 1, 1) animated:NO];
	}
    if (_refreshHeaderView) {
        [_refreshHeaderView showRefreshingHeader:YES];
    }

}

关键点在于:1、设置滚动区域;2、将refreshHeaderView设置为loading状态,从而使其显示刷新中的UI效果。

如上,setState函数是私有方法,还是不要直接改成实例方法的好,毕竟只有这一种情况下需要人为设定状态,因此自己写了个showRefreshingHead的方法,在里面设置状态。

这样就可以在一进入列表,还是空的时候,就显示顶部的refreshHeader。实际应用中,将空列表换成一个自定以的loadingView背景图片之类的,UI效果就更好一些。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值