源码地址
使用原文:
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