in iOS 7 viewForHeaderInSection section is starting from 1 not from 0

14,793

Solution 1

Just encountered exactly the same issue, and the resolution turns out very simple.

Just implement this delegate method:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

Form Apple UITableViewDelegate Protocol Reference, it mentioned

Discussion

The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForHeaderInSection: is also implemented.

Solution 2

Swift 3 Version:

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 60
}
Share:
14,793

Related videos on Youtube

Bhavesh Lathigara
Author by

Bhavesh Lathigara

iOS Lead

Updated on June 21, 2022

Comments

  • Bhavesh Lathigara
    Bhavesh Lathigara almost 2 years

    I am dealing with UITableView in my project and this project is created in Xcode 4.5 and now I am working with Xcode 5, so my question is when I will run my project in iOS 6 , the viewForHeaderInSection method section is starting from 0 it's ok but If I will use iOS 7 to run viewForHeaderInSection section is starting from 1 not from 0

    What is the problem is there any UITableView frame's problem or not

    I can't understand what is going on

    Thanks in Advance

  • spstanley
    spstanley over 10 years
    I was having the same problem until I realized the frame of my section header view had origin.y set to something other than zero.
  • jrturton
    jrturton over 10 years
    Quite ridiculous that this is necessary even if you've set the table view's section header height property.
  • testing
    testing over 9 years
    What about Auto Layout?
  • Lolloz89
    Lolloz89 almost 9 years
    Yep, this is correct. Also check the UITableViewDelegate of your UITableView is not nil.
  • Satheesh
    Satheesh over 7 years
    Thanks it helped me but does not make sense to override two methods for header.
  • Krunal Nagvadia
    Krunal Nagvadia about 4 years
    Even after implement above method. I'm still facing same issue