1

My app shows this in the 4.3.1 simulator                   and this in the 5.0 simulator.

4.3.1 simulator5.0 simulator

This is the code:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
   return @""; 
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[Singleton sharedInstance] getTitleSectionView:segmentedControl.selectedSegmentIndex inDay:section];
}
-(UIView *)getTitleSectionView:(int)week inDay:(int)day;
{
UILabel *lab=[[[UILabel alloc]init]autorelease];
lab.frame=CGRectMake(5, 0,320,20);
lab.text=[[Singleton sharedInstance] getTitleSection:week inDay:day];
lab.backgroundColor=[UIColor clearColor];
lab.textColor=[UIColor whiteColor];
lab.font = [UIFont fontWithName:@"Arial" size:14];

UIImageView * imv = [[[UIImageView alloc]initWithFrame:CGRectMake(0,0, 320, 20)]autorelease];
imv.image=[UIImage imageNamed:@"section-header-bg.png"];

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]autorelease];
[view addSubview:imv];
[view addSubview:lab];

    Week *currentWeek = nil;
    if(week)    
        currentWeek = nechetNedel;
    else        
        currentWeek = chetNedel;

    NSMutableArray *dayArray = [currentWeek.days objectAtIndex:day];
    if([dayArray count] >0)
        return view;
    return nil;
}

What can be the problem, why does lines of sections appear in the 5.0 simulator? I tried to delete the method - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section but it did not help. I delete this method(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section and the lines disappear

Pavel
  • 127
  • 2
  • 11

1 Answers1

5

You should return nil for empty sections

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

and

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

should return 0

Then it will work. It is iOS 5.x issue (or feature)

NeverBe
  • 5,213
  • 2
  • 25
  • 39
  • - (UIView *)tableView: here I return nil and image for title not show, but show gray line, - (CGFloat)tableView: if here I return 0. I didn't see the image of this method - (UIView *)tableView: – Pavel Feb 23 '12 at 18:13
  • it work, but why in IOS 4.3 it worked before, and in 5.0 not work, I can't understand – Pavel Feb 23 '12 at 18:20
  • 1
    If you don't understand it then read the documentation. The release notes for iOS 5.0 quite clearly call this point out: "[In iOS 5] Returning nil from the tableView:viewForHeaderInSection: method (or its footer equivalent) is no longer sufficient to hide a header. You must override tableView:heightForHeaderInSection: and return 0.0 to hide a header." – matt Feb 23 '12 at 18:24