Evgeniy Kleban Evgeniy Kleban - 1 year ago 68
iOS Question

Add section header view to table

I wonder what i'm doing wrong:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
/* Table header */

HeaderView *tableHead = [[HeaderView alloc]initWithFrame:CGRectMake(0, 0, self.myTableView.frame.size.width, 40)];
[tableHead initialize];
return tableHead;

My view class is simple:

@interface HeaderView ()

@property (nonatomic) UILabel *headerLbl;


@implementation HeaderView


self = [super init];
return self;


[self createUserInterface];
[self createConstraints];


self.backgroundColor = [UIColor defaultGray];
_headerLbl = [UILabel new];
_headerLbl.font = [UIFont systemFontOfSize:13];
_headerLbl.textColor = [UIColor fontGray];
_headerLbl.numberOfLines = 0;
[self addSubview:_headerLbl];


[_headerLbl mas_makeConstraints:^(MASConstraintMaker *make) {



That method suppose to create header view for my table, but it doesn't.

Answer Source

Add this method

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download