.h文件
#import <UIKit/UIKit.h>
@interface HomeHeadView : UITableViewHeaderFooterView
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
+ (instancetype)homeHeadViewWithTableview:(UITableView *)tableView;
@end
.m文件
#import "HomeHeadView.h"
@implementation HomeHeadView
- (void)awakeFromNib{
[super awakeFromNib];
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
NSArray * nibs = [[NSBundle mainBundle] loadNibNamed:@"HomeHeadView" owner:nil options:nil];
HomeHeadView * headView = nibs.lastObject;
self = headView;
}
return self;
}
+ (instancetype)homeHeadViewWithTableview:(UITableView *)tableView{
static NSString * reuseid = @"HomeHeadView";
HomeHeadView * headView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseid];
if (headView == nil) {
headView = [[HomeHeadView alloc] initWithReuseIdentifier:reuseid];
}
return headView;
}
使用
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
HomeHeadView * headView = [HomeHeadView homeHeadViewWithTableview:tableView];
return headView;
}
网友评论