Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heightForHeaderInSection not getting called?

I want to change the tableHeader height, font, etc...

I implemented UITableViewDelegate, UITableViewDataSource and added heightForHeaderInSection and viewForHeaderInSection. But these two methods are not getting called. Other methods such as numberOfRowsInSection / cellForRowAtIndexPath are working fine. I can see the table but with no header :(

Any idea?

here is the code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.poHeader.itemList count];
}

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

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NSLog(@"*******height");
    return 44.0;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    NSLog(@"***in viewForHeader In section");

    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(2, 166, 300.0, 44.0)];
    UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor blackColor];
    headerLabel.highlightedTextColor = [UIColor whiteColor];
    headerLabel.font = [UIFont systemFontOfSize:13];
    headerLabel.frame = CGRectMake(2, 166, 300.0, 44.0);

    headerLabel.text = @"Part No.   Description   Ext Cost"; // i.e. array element
    [customView addSubview:headerLabel];

    return customView;
}
like image 494
Vish Avatar asked Jan 12 '12 17:01

Vish


Video Answer


1 Answers

Almost a year later, but I guess you have only set the data source and not the delegate?

You'll have to have something like this in your controller:

myTableview.delegate = self;
myTableview.dataSource = self;

You mentioned that numberOfRowsInSection / cellForRowAtIndexPath are getting called. Both belong to UITableViewDataSource and not to UITableViewDelegate.

like image 96
Klaas Avatar answered Nov 28 '22 15:11

Klaas