当前位置: 动力学知识库 > 问答 > 编程问答 >

uitableview - 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)?

网友答案:

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

网友答案:
self.edgesForExtendedLayout=UIRectEdgeNone;

should fix this issue.

网友答案:

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)];

}

网友答案:

Place the following code in your viewcontroller's viewdidload.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.automaticallyAdjustsScrollViewInsets = NO;
}
网友答案:
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)];
    }
}
网友答案:

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);
网友答案:

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

网友答案:

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

网友答案:

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

网友答案:

The fastest workaround for me was something like this:

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
分享给朋友:
您可能感兴趣的文章:
随机阅读: