IOS UITableView Hide Header Space

In the view controller, I only have a UITableView. In IB, I made the height of the header and footer equal to 1, and also added the following code, but even above the first cell there is a lot of header space. I want to get rid of this space. Even the scrollbar starts from the first cell, and not from the top.

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
CGFloat height = 0.0001;
return height;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
CGFloat height = 0.0001;
return height;
}

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// Create Empty View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,
                                                        [self tableView:self.visitorlistsTv heightForHeaderInSection:section]) ];
return view;
}

-(UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
// Create Empty View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,
                                                        [self tableView:self.visitorlistsTv heightForFooterInSection:section]) ];
return view;

}

Using the above code, the bottom is hidden. But also can not hide the title.

After looking at other links for the solution, I also added a TableView to the view, added restrictions on the table view, but still part of the header is still them.

Where am I mistaken? How to get rid of it?

+4
source share
6

UITableView, contentInset height:

self.tableView.contentInset = UIEdgeInsetsMake(-20.0f, 0.0f, 0.0f, 0.0f);

, .

, (), , .

+6

( iOS 10), .

, 0 . , .

: , - :

self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

, , , .

, , , .

+1

, , , / . , - . viewForHeader/Footer, - .

0

self.tableView.contentInset =UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)

self.tableView.contentInset = UIEdgeInsetsMake (-75.0f, 0.0f, 0.0f, 0.0f);

0

, contentOffset Y :

- (void)viewDidLayoutSubviews
{
  UITableViewCell *firstCell = (self.tableView.visibleCells.count > 0?self.tableView.visibleCells[0]:nil);

  [super viewDidLayoutSubviews];

  // Get rid of the defaut header height.
  self.tableView.contentInset = UIEdgeInsetsMake(-firstCell.frame.origin.y, 0, 0, 0);
}
0

uitableview.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 {
    return 0.002f;// set this...
 }
-1
source

All Articles