iOS6新特性UIRefreshControl下拉刷新与上拉加载

1、内容简介

模拟QQ空间移动客户端实现的iOS6 pull refresh data新特性,自己另外加上了上拉加载的功能,上拉为线下比较流行的滑动到底部最后一条后自动更新,增强了用户的体验感觉.而不再支持以前的上拉到一定程度后释放加载

链接:PullRefreshTableview

2、实现方法

先导入:

CoreText.framework框架

在需要实现的类中导入

#import "PullRefreshTableView.h"

添加协议:

<PullRefreshDelegate>

创建成员变量

@property (strong ,nonatomic)PullRefreshTableView *PullTableView;

在控制器中添加列表对象:

    PullRefreshTableView * table =[[PullRefreshTableView alloc] initWithFrame:self.view.frame withDelegate:self];
    table.dataSource=self;
    table.delegate=self;
    table.backgroundColor=[UIColor clearColor];
    self.PullTableView=table;
    [self.view addSubview:_PullTableView];
    [self.PullTableView LoadDataBegin];/*刷新数据*/


#pragma mark - Scroll

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.PullTableView scrollViewDidPullScroll:scrollView];
}

实现UITablVIew Delegate / Datasource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return pages;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * strCell =@"cell";
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:strCell];
    if (!cell) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
        UIView * v=[[UIView alloc] initWithFrame:cell.frame];
        v.backgroundColor=[UIColor whiteColor];
        cell.backgroundView=v;
    }
    cell.textLabel.text=[NSString stringWithFormat:@"cellIdentifier%d",indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString * message =[NSString stringWithFormat:@"您点击的是第%d行",indexPath.row];
    UIAlertView * alert =[[UIAlertView alloc] initWithTitle:@"提示"
                                                    message:message
                                                   delegate:self
                                          cancelButtonTitle:@"确认"
                                          otherButtonTitles:nil, nil];
    [alert show];
}




对应的触发方法

/*下拉刷新*/
- (void)upLoadData{
    pages=14;
    [self.PullTableView reloadDataPull];
}

/*上拉加载*/
- (void)refreshData{
    pages+=1;
    if (pages>16) {
        self.PullTableView.reachedTheEnd=NO;
    }
    [self.PullTableView reloadDataPull];
   
}







这里只是粗略的写了一个实现的小例子,还有很多很多地方需要完善



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值