HeightForHeaderInSection not getting a call?

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

I implemented UITableViewDelegate , UITableViewDataSource and added heightForHeaderInSection and viewForHeaderInSection . But these two methods are not called. Other methods like numberOfRowsInSection / cellForRowAtIndexPath work fine. I see a table, but without a title :(

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"; // ie array element [customView addSubview:headerLabel]; return customView; } 
+6
source share
2 answers

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

Your controller should have something like this:

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

You mentioned that calls to numberOfRowsInSection / cellForRowAtIndexPath are called. Both relate to UITableViewDataSource , and not to UITableViewDelegate .

+17
source

for quick, in addition to setting up the delegate, declare a UITableViewDelegate match for the class or extension in question

0
source

Source: https://habr.com/ru/post/1390685/


All Articles