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;
}
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With