ios 上拉加载更多tableview MJRefresh

源码地址

https://github.com/CoderMJLee/MJRefresh#%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B002-%E5%8A%A8%E7%94%BB%E5%9B%BE%E7%89%87


使用原文:


http://www.open-open.com/lib/view/open1417098720862.html


示例:



#import "ViewController.h"
#import "MJRefresh.h"
#import "MJRefreshGifHeader.h"
@interface ViewController ()

@end

@implementation ViewController
@synthesize testTable;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.testTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
    testTable.dataSource=self;
    testTable.delegate=self;
    [self.view addSubview:testTable];
    testTable.mj_footer= [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    testTable.mj_header=[MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
}
-(void)loadMoreData{
    NSLog(@"loadmore");
    [testTable.mj_footer endRefreshing];
}
-(void)refresh{
    NSLog(@"refresh");
    [testTable.mj_header endRefreshing];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//datasource count
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //    NSLog(@"count:%d",[self.recordWholeArray count]);
    return 20;
    
}
//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
//设置列表数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    @try {
        
        static NSString *identifier = @"cell";
        UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[UITableViewCell  alloc]initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:identifier];
            int cellWidth=cell.frame.size.width;
            float labWidth=cellWidth/5;
            float labHeight=20;
            //int cellHeight=cell.frame.size.height;
            //名称
            UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labWidth, labHeight)];
            label1.textColor=[UIColor blackColor];
            [label1 setNumberOfLines:1];
            label1.text=@"名称";
            label1.textAlignment=NSTextAlignmentCenter;
            [label1 setFont:[UIFont boldSystemFontOfSize:15]];
            [cell.contentView addSubview:label1];
            //名称
            UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(0, labHeight, labWidth, labHeight)];
            lab1.tag=1;
            lab1.textColor=[UIColor grayColor];
            [lab1 setNumberOfLines:1];
            lab1.textAlignment=NSTextAlignmentCenter;
            [lab1 setFont:[UIFont systemFontOfSize:14]];
            [cell.contentView addSubview:lab1];
        }
        
        UILabel *label1_1 = (UILabel *)[cell viewWithTag:1];
        label1_1.text = @"kao";
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        return cell;
    }
    @catch (NSException *exception) {
        NSLog(@"%@   %@",[exception name],[exception reason]);
        return nil;
    }
}
@end


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值