UITableView content overlaps Status Bar when UISearchBar is active
I have search this for hours and my final result was to put this line in viewDidLoad: self.extendedLayoutIncludesOpaqueBars = YES;
Problem solved :)
Try setting the definesPresentationContext
in viewDidLoad
of your TableViewController
Swift
override func viewDidLoad() { super.viewDidLoad() definesPresentationContext = true}
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; self.definesPresentationContext = YES;}
Here's what worked for me:
DO:
- Use UISearchController (not a separately placed UISearchBar)
- Place your VC in a UINavigationController if it isn't already. Set the nav not to "Show Navigation Bar" if desired.
- Use autolayout for the UITableView (not springs and struts) and pin the top of the table to the top of the VC's view.
- Add this delegate method:
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { return UIBarPositionTopAttached;}
DON'T:
- Fiddle with edgesForExtendedLayout
- Fiddle with extendedLayoutIncludesOpaqueBars
- Fiddle with the table's contentInset