IOS UITableView contentOffSet no longer hides title when returning from exact detail view

I use the code below in the root view controller to hide the UITableView header (there is a UISearchbar in the header). It works when the application starts and displays a tableView. However, subsequently, when the row is selected, the detailed view is clicked and the user pushes the detailed view, the uitableview header is now displayed in the root view, and this is not what I expected.

Here are the relevant functions:

- (void) viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES animated:animated]; [super viewWillAppear:animated]; self.tableView.contentOffset = CGPointMake(0, self.tableView.tableHeaderView.frame.size.height); //it as if the line above is ignored on when returning from a pushed detail view } - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // theContentOffSet works when I put it hear, but then the user can see it which is not desired } 

String '[self.navigationController setNavigationBarHidden: YES animated: animated];' certainly part of the problem, since the code works without it, and the tableView title scrolls out of view. However, the requirement for the root view is that the navigation bar is hidden, but is displayed in the detail view.

+6
source share
2 answers

Looking around for a while, I found the following https://devforums.apple.com/message/315519#315519 message that solves this problem.

 -(void)viewWillAppear:(BOOL)animated { [self performSelector:@selector(updateContentOffset) withObject:nil afterDelay:0.0]; } - (void)updateContentOffset { self.tableView.contentOffset = CGPointMake(0, savedContentOffsetY); } 

Of course, in viewWillDisappear you can save the content offset as follows:

 savedContentOffsetY = self.tableView.contentOffset.y; 

And in your viewDidLoad ,

 savedContentOffsetY = self.tableView.tableHeaderView.frame.size.height; 
+16
source

I have a search and tried a lot, but nothing helped. Finally, the following code helped me. You can add code to your viewDidLoad () method:

 self.edgesForExtendedLayout = UIRectEdgeNone; 
+1
source

Source: https://habr.com/ru/post/889147/