I have a table view with the following implementation,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.postsArr count];
}
This is working fine before I set the header view titles. I set the header view titles like,
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
NSString *sectionName;
if (self.newsSegmentControl.selectedSegmentIndex == 1) {
NSLog(@"section:%ld",(long)section-1);
BTPost *sectionPost = [self.postsArr objectAtIndex:section];
NSString *actDate = [NSString stringWithFormat:@"/Date(%ld)/",sectionPost.timeStamp];
NSString *nDate = [[[[actDate componentsSeparatedByString:@"("] objectAtIndex:1] componentsSeparatedByString:@")"] objectAtIndex:0];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:([nDate doubleValue] / 1000)];
NSString *dayString = [self getDayLabel:date];
sectionName = dayString;
}else{
return nil;
}
return sectionName;
}
When I'm running this,
[![https://i.stack.imgur.com/aesU3.png][1]][1]
I got this kind of output. When I'm scrolling down it shows the section headers correctly. But when I'm scrolling up it shows the header with an empty title. How may I fix this?