in iOS 7 viewForHeaderInSection section is starting from 1 not from 0
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
}
Related videos on Youtube
Comments
-
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 , theviewForHeaderInSection
method section is starting from 0 it's ok but If I will use iOS 7 to runviewForHeaderInSection
section is starting from 1 not from 0What is the problem is there any
UITableView
frame's problem or notI can't understand what is going on
Thanks in Advance
-
spstanley over 10 yearsI 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 over 10 yearsQuite ridiculous that this is necessary even if you've set the table view's section header height property.
-
testing over 9 yearsWhat about Auto Layout?
-
Lolloz89 almost 9 yearsYep, this is correct. Also check the UITableViewDelegate of your UITableView is not nil.
-
Satheesh over 7 yearsThanks it helped me but does not make sense to override two methods for header.
-
Krunal Nagvadia about 4 yearsEven after implement above method. I'm still facing same issue