ios - Search results not aligned with searchbar for UISearchController -
i trying upgrade uisearchdisplaycontroller
uisearchcontroller
, having lot of strange problems it. current problem search results not align searchbar. in portrait mode, there small gap between searchbar , first search result:
(i have coloured background of results tableview yellow, show extend)
for landscape mode, opposite true: searchbar overlaps top of results:
strangly enough, if rotate view results view still visible, comes out perfectly.
my setup pretty standard approach, searchbar in navigation bar, , search results in separate uitableviewcontroller
. code in original view controller:
- (void) viewdidload { [super viewdidload]; searchresults *searchresults = [[searchresults alloc] init]; searchcontroller = [[uisearchcontroller alloc] initwithsearchresultscontroller:searchresults]; searchcontroller.searchresultsupdater = searchresults; self.navigationitem.titleview = searchcontroller.searchbar; searchcontroller.hidesnavigationbarduringpresentation = no; searchcontroller.dimsbackgroundduringpresentation = yes; self.definespresentationcontext = yes; }
the searchresults
standard uitableviewcontroller
subclass, no special formatting.
my suspicion was due incorrect contentinset of tableview, printed in viewwilllayoutsubviews
, confirmed suspicion.
how work around apparent bug in uisearchcontroller
?
note: have tried use combination of edgesforextendedlayout
, automaticallyadjustsscrollviewinsets
, , extendedlayoutincludesopaquebars
results tableview.
edit: have logged bug apple this: https://openradar.appspot.com/radar?id=6138130516148224
i have found work-around seems work in situations. still appreciate if can spot have done wrong in original code.
for work-around, in searchresults class, add following:
- (void) viewwilllayoutsubviews { // workaround bug in uisearchcontroller: cgfloat topinset = self.toplayoutguide.length + (_searchcontroller ? _searchcontroller.searchbar.frame.size.height : 44); uiedgeinsets insets = self.tableview.contentinset; if (topinset != insets.top) { // set correct insets insets.top = topinset; self.tableview.contentinset = insets; // scroll top self.tableview.contentoffset = cgpointmake(0, -topinset); } }
Comments
Post a Comment