2
votes

got a UITableViewStyleGroupedand UITableViewStylePlain by changes in storyboard, found that, top edge of plain table view sticks to navigation bar, while top gap in grouped style somehow because of header view.

enter image description here

But, as picture show, gap "a" is bigger than "b", why? Are there any hidden elements around "a"? How to manage this gap so that it could be also stuck with bar?

What's the default size of gap "a" and "b"? How to make "a" equal to "b", like "setting"

enter image description here

below are my try-out


tried set heightForHeaderInSection: and viewForHeaderInSection: like below

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

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView * header = [[UIView alloc] init];
header.backgroundColor = [UIColor redColor];
[self.view addSubview:header];

return header;
}

enter image description here


tried heightForFooterInSection: and viewForFooterInSection:, like below

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.0f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView * footer = [[UIView alloc] init];
footer.backgroundColor = [UIColor yellowColor];
[self.view addSubview:footer];
return footer;
}

enter image description here


It looks neither of them work as expected, gap "a" is always there and not changed.

The weird is, height of header and footer is still there, looks a minium height,

even if setting their height zero.

7
I've run into the same problem. My conclusion is that if you return 0, then it defaults to display a standard empty section header with a default height. It won't even call the methods for the header view and the header text. If you return a different value, e.g. 0.5, then it calls the header view and text methods and displays the correct section header with the specified height. - Codo

7 Answers

1
votes

Not sure exactly why your issue is occurring, but a workaround to get the grouped tableview "stuck" to the bottom of the navigation bar:

CGFloat myInset = *HEIGHT OF GAP A*
self.tableView.contentInset = UIEdgeInsetsMake(-myInset, 0, 0, 0);
1
votes

Just add this code in ViewDidLoad method:

self.automaticallyAdjustsScrollViewInsets = NO;
0
votes

I hope it's can help you . I am thinking you need to change footer height .

implement those UITableView-delegate methods:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return 50.0f;
}

or this delegate methods

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

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
0
votes

This is a bug I have opened from the first beta. It's working with this option meanwhile:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        if([UIScreen mainScreen].bounds.size.height == 568.0) {
            //iphone5
            sectionsTableView.frame = CGRectMake(0, 0, 320, 568);
        }
        else {
            //iphone4s
            sectionsTableView.frame = CGRectMake(0, 0, 320, 480);
        }
    }

Bugreport issue #14310190

0
votes

Before each section, you have a header. After each section, you have a footer. What you have marked as "a" is the header of section 0. What you have marked as "b" is the combination of the footer of section 0 and the header of section 1.

So to have the same appearance as the Settings app, you want code like this:

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return 20.0f;
    return 10.0f;
}

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

Note that returning 0 will not work. It seems to have the effect that the table view reverts to some default empty header or section.

0
votes

For those of you still interested, the reason why there's the space at the top of the table view, is because that's the default header of the TableView. To get ride of it, just add this to your tableViewController

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

That will draw it right under the top of the view controller. You can change the value of 0.0 to whatever you so desire.

0
votes

Return the minimum value (not 0) in the table view's heightForFooterInSection API (say 0.1). This will remove the default space (which is around 10 px) from the bottom of the section as you shown in yellow and red color.