您的位置:首页 > 其它

使用MJRefresh实现上拉加载,下拉刷新功能!!

2015-08-04 10:42 441 查看
注:本文转自于:http://blog.csdn.net/mitianbingshi/article/details/17076273

 

#import "HomeViewController.h"  

#import "MJRefresh.h"  

  

@interface HomeViewController ()  

{  

    MJRefreshHeaderView *_header;  

    MJRefreshFooterView *_footer;  

  

}  

  

@property (nonatomic ,retainUITableView *mainTableView;  

@property (nonatomic ,retainNSMutableArray *mainDataList;  

  

@end  

  

@implementation HomeViewController  

@synthesize mainTableView,mainDataList;  

  

  

- (void)viewDidLoad  

{  

    [super viewDidLoad];  

    mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];  

    mainTableView.delegate = self;  

    mainTableView.dataSource = self;  

    [self.view addSubview:mainTableView];  

    mainDataList = [[NSMutableArray alloc]init];    

    // 刷新功能  

    _header = [[MJRefreshHeaderView alloc] init];  

    _header.delegate = self;  

    _header.scrollView = mainTableView;  

    //添加上拉加载更多  

    _footer = [[MJRefreshFooterView alloc] init];  

    _footer.delegate = self;  

    _footer.scrollView = mainTableView;  

}  

#pragma mark 代理方法-进入刷新状态就会调用  

- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView  

{  

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];  

    formatter.dateFormat = @"HH : mm : ss.SSS";  

    if (_header == refreshView)  

    {  

        //下拉刷新数据请求********************************  

        // 2秒后刷新表格  

        [self performSelector:@selector(reloadDeals) withObject:nil afterDelay:2];  

          

    } else {  

        //上拉刷新数据请求**************************************  

        // 2秒后刷新表格  

        [self performSelector:@selector(reloadDeals) withObject:nil afterDelay:2];  

    }  

}  

  

- (void)reloadDeals  

{  

    [mainTableView reloadData];  

    // 结束刷新状态  

    [_header endRefreshing];  

    [_footer endRefreshing];  

}  

  

  

-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  

{  

    return mainDataList.count;  

}  

  

-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  

{  

    return 40;  

}  

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  

{  

    static NSString *cellindentifier = @"cell";  

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellindentifier];  

    if (!cell) {  

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellindentifier];  

    }  

    return cell;  

  

}  

  

- (void)didReceiveMemoryWarning  

{  

    [super didReceiveMemoryWarning];  

    // Dispose of any resources that can be recreated.  

}  

  

@end  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: