ios - UISearchBar will not respond in UISplitviewController Master -


i have pretty standard setup of uitableview master controller in uisplitviewcontroller, universal ios9 app.

again, standard fare, inserted uisearchbar header of table.

self.searchcontroller = [[uisearchcontroller alloc] initwithsearchresultscontroller:nil]; self.searchcontroller.searchresultsupdater = self; self.searchcontroller.dimsbackgroundduringpresentation = no; self.searchcontroller.hidesnavigationbarduringpresentation = no;  [self.searchcontroller.searchbar sizetofit]; self.tableview.tableheaderview = self.searchcontroller.searchbar;  self.definespresentationcontext = yes; 

no need showing rest of code, search , work expected, on iphone. issue search bar not ever receive focus or present keyboard when run on ipad. no response, seems not receive touches. not respond programmatically attempting becomefirstresponder.

nothing happens.

the search bar visible , placed appropriately, there no underlay or overlay issues.

it works fine on iphone. receives touch, presents keyboard, search works. presumably there critical difference in presentation when uisplitviewcontroller collapsed. hours of search, pouring through documentation , every tutorial come across, have not found similar experience surprising.

additional note: if use multi tasking shrink split view collapsed on ipad, search bar works, same on iphone. has collapsed state of split view.

update: (getting closer)

after further experimentation find search bar works on ipad if start app in landscape. in portrait mode, primary controller hidden. slides in selection of displaymodebuttonitem, set leftbarbuttonitem of detail controller. when searchbar breaks , no longer respond touches.

if start in landscape, rotate portrait, stops working well. rotating landscape not fix it. once broke, stays broke until restart.

i tried moving definespresentationcontext viewwillappear method of master controller, had no effect.

further update:

another unexpected circumstance there no problem search bar @ on iphone 6plus. works regardless of orientation, collapsed or no , doesn't matter state starts in. expect same ipad when in landscape orientation. works on iphone.

i still have not figured out. latest attempt fix, moved search controller initialization viewdidlayoutsubviews method. no change whatsoever.

also, noticed when search active, keyboard onscreen, if rotate ipad keyboard goes away search bar remains active. didn't realize @ first, saw cancel button still displayed. won't receive touches , not have keyboard, apparently still first responder.

sample project uploaded github: github repository

note- there no issue until added uisplitview delegate methods project. wanted add question right away, so, haven't yet tried see how these delegate methods affect search bar issue created there somewhere.

update:

i tried few more variations no success.

  • move search bar section header. no joy.
  • put search bar in uiview content view. no joy.
  • remove search bar on disappear, reinsert on did appear. no joy.
  • manipulate size of search bar frame ensure not clipped. no joy.

i looked @ view hierarchy in profiler, search bar top level, not covered else.

final wrap:

@tomswift workaround did correct issue on ipad. on further testing, found broke iphone ui. presumably, more issue own setup , timing of creation of master/detail view controllers. seem important objects no longer created in time perhaps detail view controller didn't exist yet. poked around fix moving critical items app delegate became unwieldy , couldn't narrow down, hacked fix with:

if (ui_user_interface_idiom() == uiuserinterfaceidiompad) {     splitviewcontroller.preferreddisplaymode = uisplitviewcontrollerdisplaymodeallvisible; } 

a more elegant solution had, has taken enough of time. works now. radar filed- 28304096

this bug in uisplitviewcontroller and/or uisearchcontroller. file radar w/ apple , attach code sample.

i think bug involves uisplitviewcontroller.displaymode uisplitviewcontrollerdisplaymodeautomatic. when change preferreddisplaymode uisplitviewcontrollerdisplaymodeallvisible starts work:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     // override point customization after application launch.     uisplitviewcontroller *splitviewcontroller = (uisplitviewcontroller *)self.window.rootviewcontroller;     uinavigationcontroller *navigationcontroller = [splitviewcontroller.viewcontrollers lastobject];     navigationcontroller.topviewcontroller.navigationitem.leftbarbuttonitem = splitviewcontroller.displaymodebuttonitem;     splitviewcontroller.delegate = self;     splitviewcontroller.preferreddisplaymode = uisplitviewcontrollerdisplaymodeallvisible;      return yes; } 

the main thing changes default layout portrait on ipad, understand may not ideal. played setting preferreddisplaymode uisplitviewcontrollerdisplaymodeallvisible setting uisplitviewcontrollerdisplaymodeautomatic; worked great until screen orientation changed - broke again. might have luck going further down path.

i made following addition in appdelegate, force search controller deactivate on displaymode change. (i had expose searchcontroller property publicly on masterviewcontroller).

- (void)splitviewcontroller:(uisplitviewcontroller *)svc willchangetodisplaymode:(uisplitviewcontrollerdisplaymode)displaymode {      uinavigationcontroller *navigationcontroller = [svc.viewcontrollers firstobject];     masterviewcontroller* mvc = (masterviewcontroller*) navigationcontroller.topviewcontroller;     [mvc.searchcontroller setactive: no]; } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -