Reputation: 3562
I have a UITableViewController with an imbedded UISearchDisplayController. In iOS 7 the search box is under the status bar. Is there a way in interface builder to offset the tableview so that the search bar is not covered by the status bar (and still use the UITableViewController and UISearchDisplayController setup)?
Upvotes: 14
Views: 13741
Reputation: 647
after data loaded into table view just call this in iOS 6 / 7
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
But make sure that the search bar is added as header to the table view
Upvotes: 1
Reputation: 21
I had to adjust the tableview's contentOffset
and contentInset
. My tableviewcontroller triggered by modal segue is already embedded in a navigation controller upstream in the storyboard. Adjusting the content inset by the height of the status bar and content offset by the height of the search bar displays the tableview beginning at the first cell. The search bar displays when the user pulls down the tableview.
self.tableView.contentOffset = CGPointMake(0, 44.0);
self.tableView.contentInset = UIEdgeInsetsMake(20.0, 0.0, 0.0, 0.0);
Upvotes: 2
Reputation: 1196
self.edgesForExtendedLayout = UIRectEdgeNone;
...
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
if (navigation.hiden) {
[self.tbview setContentOffset:CGPointMake(0, -20)];
[self.tbview setContentInset:UIEdgeInsetsMake(20, 0, 0, 0)];
}
else {
[self.tbview setContentOffset:CGPointMake(0, -20)];
[self.tbview setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
Upvotes: 2
Reputation: 516
Place the following code in your viewcontroller's viewdidload.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
}
Upvotes: 2
Reputation: 2684
All you have to do for this is select the view controller your UITableView is housed in and show the Attributes Inspector. In Attributes Inspector, uncheck Extend Edges -> Under Top Bars and Under Bottom Bars. This worked for me when my UITableview was loading up underneath the Nav bar and Tab Bar
Upvotes: 1
Reputation: 4746
Feels a bit hacky but this one worked for me:
[self.tableView setContentInset:UIEdgeInsetsMake(self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height, 0, 0, 0)];
and if you're working for both orientations:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self.tableView setContentInset:UIEdgeInsetsMake(self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height, 0, 0, 0)];
}
Upvotes: 4
Reputation: 1209
You would have to embed it in a UINavigationController
, then in the navVC
, simply uncheck the Shows Navigation Bar
Upvotes: 7
Reputation: 1046
self.edgesForExtendedLayout=UIRectEdgeNone;
should fix this issue.
Upvotes: 14
Reputation: 3562
I found the culprit. Setting the layout option "Adjust Scroll View Insets" to on did the trick.
Upvotes: 1