timpone timpone - 1 year ago 59
iOS Question

why extra space is at top of UITableView - simple

I'm picking up some iOS programming and am trying to put a UITableView into a storyboard. Unfortunately, I am trying to put the content at the top of the view but it is putting in some space. I have tried to adjust the values in the inspector for View -> Mode but this doesn't seem to have any effect.

I have made the background green and put a border color to show the issue. I'm not a sophisticasted iOS dev, so I'd assume that this is the simplest solution and not something complex. How do I make the contents of the table view sit flush with the top? I've seen this Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7 but not sure if it's related.

thx for any help

enter image description here

Edit #1

Updated with changes and screen shot of properties for this table view

enter image description here

enter image description here

enter image description here

Answer Source

Yes, that other question is very much related. UITableViewStyleGrouped divides each section into a "group" by inserting that extra padding…similar to what it did pre-iOS7, but clear instead of colored by default, and just at the top instead of all the way around. If you don't want the padding by default, use UITableViewStylePlain.

Otherwise, if you need to keep the style the same, do what this other posted from that link recommended and change the content inset:

self.tableView.contentInset = UIEdgeInsetsMake(-36, 0, 0, 0);

Or do what this poster suggested and set the tableViewHeight to .-1, i.e. nearly 0:

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];