datinc
datinc

Reputation: 3562

iOS 7 - UITableViewController with search is under status bar

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

Answers (9)

Bassl Kokash
Bassl Kokash

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

james_d
james_d

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

user501836
user501836

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

Ali Shahid
Ali Shahid

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

Jesse
Jesse

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

ED-209
ED-209

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

Kyle Fang
Kyle Fang

Reputation: 1209

You would have to embed it in a UINavigationController, then in the navVC, simply uncheck the Shows Navigation Bar enter image description here

Upvotes: 7

Filippo
Filippo

Reputation: 1046

self.edgesForExtendedLayout=UIRectEdgeNone;

should fix this issue.

Upvotes: 14

datinc
datinc

Reputation: 3562

I found the culprit. Setting the layout option "Adjust Scroll View Insets" to on did the trick.

Upvotes: 1

Related Questions