Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra space above search bar when UISearchDisplayController is active

I have a popover with a UITableViewController as the content view controller. The table view has a UISearchBar as its header view.

Now, on iOS 6 everything looks good when the UISearchDisplayController becomes active. But, on iOS 7 there will be an extra space above the search bar.

The extra space above the search bar on iOS 7

So how can I get rid of this extra space above the search bar on iOS 7?

like image 550
Hejazi Avatar asked Sep 22 '13 15:09

Hejazi


1 Answers

The solution is to set the property edgesForExtendedLayout of the UITableViewController to UIRectEdgeNone.

- (void)viewDidLoad {
    [super viewDidLoad];

    if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { /// iOS 7 or above
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
}

This property has the value UIRectEdgeAll by default. Which means all edges of the view will be extended to keep an extra space for the status bar (the height of the space above the search bar is exactly 20px, the same height of the status bar).

like image 117
Hejazi Avatar answered Sep 20 '22 04:09

Hejazi