How to fix the problem of UITableview dislocation in iOS

  • 2021-09-24 23:52:30
  • OfStack

Problem description:

Question 1: When an navigation navigates into UITabBarController TabBar, there are multiple pages, and there is tableView under the page. When I enter Tableview, the above two lines of table are blocked. When I click in and come back, there is no visible one. It is found that the upward position of table is 44PT, which is just the position of an top bar. (But getting from this page's parent page push to this page is still blocked, but getting out of this page's child page pop is not blocked.)

Problem 2: When doing UISearchBar and UISearchDisplayController, I encountered a problem. When clicking on the search bar, the position of the shaded part appeared deviation


- (void)viewDidLoad { 
 [super viewDidLoad]; 
 //self.automaticallyAdjustsScrollViewInsets = NO; 
 self.edgesForExtendedLayout = UIRectEdgeNone; 
} 

In iOS 7, Apple introduced a new attribute called [ UIViewController setEdgesForExtendedLayout :], which defaults to UIRectEdgeAll. When your container is navigation controller, the default layout will start at the top of navigation bar. This is why all UI elements drift up 44pt.

A quick way to fix this problem is in the method-( void)viewDidLoad Add the following 1 line of code to:


self.edgesForExtendedLayout = UIRectEdgeNone; 

In this way, the problem is fixed.


Related articles: