Hejazi
Hejazi

Reputation: 17005

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?

Upvotes: 9

Views: 4032

Answers (1)

Hejazi
Hejazi

Reputation: 17005

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).

Upvotes: 26

Related Questions