直接上代碼了
LeBaseTabView.h里面
```#import@interface LeBaseTabView : UITableView/**```
row
*/
@property (nonatomic,copy)? NSInteger (^RowAtIndexPathBlock)(UITableView *tableView,NSInteger section);
//- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
/**
section
*/
@property (nonatomic,copy) NSInteger (^numberOfSectionsInTableViewBlock)(UITableView *tableView);
/**
返回UItabLeviewcell
*/
@property (nonatomic,copy) UITableViewCell * (^cellForRowAtIndexPathBlock)(UITableView *tableView,NSIndexPath *indexPath);
/**
heightForHeaderInSection
*/
@property (nonatomic,copy) CGFloat (^heightForHeaderInSectionBlock)(UITableView *tableView,NSInteger section);
/**
heightForFooterInSection
*/
@property (nonatomic,copy) CGFloat (^heightForFooterInSectionBlock)(UITableView *tableView,NSInteger section);
/**
didSelectRowAtIndexPath
*/
@property (nonatomic,copy) void (^didSelectRowAtIndexPathBlock)(UITableView *tableView,NSIndexPath * indexPath);
/**
viewForFooterInSection
*/
@property (nonatomic,copy) UIView * (^viewForFooterInSectionBlcok)(UITableView *tableView,NSInteger? section);
/**
viewForHeaderInSection
*/
@property (nonatomic,copy) UIView* (^viewForHeaderInSectionBlock)(UITableView *tableView,NSInteger section);
@end
LeBaseTabView.m里面實現(xiàn)
#import "LeBaseTabView.h"
@implementation LeBaseTabView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
if (self = [super initWithFrame:frame style:style]) {
self.delegate = self;
self.dataSource = self;
self.estimatedRowHeight = 200;
self.rowHeight = UITableViewAutomaticDimension;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (self.RowAtIndexPathBlock) {
return self.RowAtIndexPathBlock(tableView,section);
}else{
return 0;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (self.numberOfSectionsInTableViewBlock) {
return self.numberOfSectionsInTableViewBlock(tableView);
}else{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
return self.cellForRowAtIndexPathBlock(tableView,indexPath);
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (self.heightForHeaderInSectionBlock) {
return self.heightForHeaderInSectionBlock(tableView,section);
}else{
return 0.01f;
}
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if (self.viewForFooterInSectionBlcok) {
return? self.viewForFooterInSectionBlcok(tableView,section);
}else{
return? (UIView*)[UIView new];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if (self.heightForFooterInSectionBlock) {
return self.heightForFooterInSectionBlock(tableView,section);
}else{
return 0.01f;
}
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (self.viewForHeaderInSectionBlock) {
return? self.viewForHeaderInSectionBlock(tableView,section);
}else{
return? (UIView*)[UIView new];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.didSelectRowAtIndexPathBlock) {
self.didSelectRowAtIndexPathBlock(tableView,indexPath);
}
}
@end
在controller里面調(diào)用
#import "LeBaseTabView.h"
@property (nonatomic,strong)LeBaseTabView *trackTableView;
懶加載創(chuàng)建
- (LeBaseTabView *)trackTableView{
if (!_trackTableView) {
_trackTableView = [[LeBaseTabView alloc] initWithFrame:self.scrollView.bounds style:UITableViewStyleGrouped];
_trackTableView.backgroundColor = [UIColor clearColor];
[_trackTableView registerClass:[trackTableViewCell class] forCellReuseIdentifier:@"trackTableViewCell"];
[_trackTableView addHeaderWithTarget:self action:@selector(trackHeaderRefreshing)];
[self.scrollView addSubview:_trackTableView];
}return _trackTableView;
}
實現(xiàn)回調(diào):
-(void)createUI{
__weak typeof(self)weakSelf = self;
self.trackTableView.cellForRowAtIndexPathBlock = ^UITableViewCell *(UITableView *tableView,NSIndexPath *indexPath) {
if (indexPath.section == 0) {
trackTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trackTableViewCell" forIndexPath:indexPath];
if ([weakSelf.userTrajectoryArr count]>indexPath.row) {
BXPasterList *model = weakSelf.userTrajectoryArr[indexPath.row];
cell.model = model;
}
return cell;
}else{
trackTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trackTableViewCell" forIndexPath:indexPath];
if ([weakSelf.userTrajectoryArr count]>indexPath.row) {
BXPasterList *model = weakSelf.userFriendShareArr[indexPath.row];
cell.model = model;
}
return cell;
}
};
self.trackTableView.numberOfSectionsInTableViewBlock = ^NSInteger(UITableView *tableView) {
if ([self.userFriendShareArr count]>0) {
return 2;
}
return 1;
};
self.trackTableView.RowAtIndexPathBlock = ^NSInteger(UITableView *tableView, NSInteger section) {
if (section == 0) {
return [weakSelf.userTrajectoryArr count];
}else{
return [weakSelf.userFriendShareArr count];
}
};
self.trackTableView.heightForHeaderInSectionBlock = ^CGFloat (UITableView *tableView,NSInteger section){
if(section == 1&&[self.userFriendShareArr count]) {
return 36.f;
}else{
return 0.01;
}
};
self.trackTableView.viewForHeaderInSectionBlock = ^UIView *(UITableView *tableView,NSInteger section){
if (section==1&&[self.userFriendShareArr count]) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, 36)];
view.backgroundColor = COLOR(250, 250, 250);
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 19, KSCREENWIDTH-30, 12)];
label.text = @"來自好友的分享";
label.font = FONT(12);
label.textColor = COLOR(100, 100, 100);
label.textAlignment = NSTextAlignmentLeft;
[view addSubview:label];
return view;
}else{
return nil;
}
};
self.trackTableView.didSelectRowAtIndexPathBlock = ^(UITableView *tableView, NSIndexPath *indexPath) {
}
后期加上下拉上拉 奉上demo ?