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

来源:互联网 发布:网络侦查技术有哪些 编辑:程序博客网 时间:2024/04/30 03:26

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];   }







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



原创粉丝点击