I made a UITableView and set the "delegate" and "datasource" and every time I call reloadData, it goes into the method:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.headersList count];
}
And the method:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
SectionInfo *headerInfo = (self.headerInfoArray)[section];
NSInteger numOfObjectsInSection = [[headerInfo.list objectsInList] count];
return headerInfo.open ? numOfObjectsInSection : 0;
}
And then stops! it doesn't go into the ViewForHeaderInSection: method. I have also implemented the method:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return SECTION_HEADER_HEIGHT;
}
The viewForHeaderInSection method:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UISectionHeaderView *sectionHeaderView = [[UISectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, SECTION_HEADER_HEIGHT)];
SectionInfo *sectionInfo = (self.headerInfoArray)[section];
sectionHeaderView.open = sectionInfo.open;
sectionInfo.headerView = sectionHeaderView;
sectionHeaderView.titleLabel.text = [NSString stringWithFormat:@"%@ (%lu)",sectionInfo.list.title, (unsigned long)[sectionInfo.list.objectsInList count]];
sectionHeaderView.section = section;
sectionHeaderView.delegate = self;
return sectionHeaderView;
}
You should implement heightForHeaderInSection: and set the height for the header to a value > 0.
Same issue occured with me that's because tableview didn't find height for header but as I was using automatic height calculation from xCode 9, I cannot give any explicit height value. After some experimentation I got solution, we have to override this method as,
-(CGFloat)tableView:(UITableView *)tableView
estimatedHeightForHeaderInSection:(NSInteger)section
{
return 44.0f;
}
Although I have checked both options
from storyboard as apple says, but still I got this weird error.
Please Note: This Error was shown only on IOS-10 version not on IOS-11 version. Maybe it's a bug from xCode. Thanks
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