objective c - How to collapse ViewController in UISplitViewController -


i have splitviewcontroller have instantiated in code.

mastervc = [[masterviewcontroller alloc] init]; detailviewcontroller *detailvc = [[detailviewcontroller alloc] init]; mastervc.detailviewcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:detailvc]; ... _splitviewcontroller =  [[uisplitviewcontroller alloc] init]; _navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:mastervc]; ... _splitviewcontroller.viewcontrollers = @[_navigationcontroller, mastervc.detailviewcontroller]; _splitviewcontroller.preferreddisplaymode = uisplitviewcontrollerdisplaymodeallvisible; ... self.window.rootviewcontroller = _splitviewcontroller; 

90% of time want both viewcontrollers displayed in settings app, does. there instances want toggle visibility of left _navigationcontroller few minutes , later go default 2-column setup.

how can collapse left side? way can think of redefine self.window.rootviewcontroller , set mastervc.detailviewcontroller.

isn't there more "flexible" way?

thanks

you can use display mode button item hide or show master.

detailviewcontroller.navigationitem.leftbarbuttonitem = self.splitviewcontroller.displaymodebuttonitem; detailviewcontroller.navigationitem.leftitemssupplementbackbutton = yes; 

the master-detail project provides sample code collapse splitviewcontroller. refer uisplitviewcontrollerdelegate more details.

update:

here's requested delegate code asked about:

- (bool)splitviewcontroller:(uisplitviewcontroller *)splitviewcontroller collapsesecondaryviewcontroller:(uiviewcontroller *)secondaryviewcontroller ontoprimaryviewcontroller:(uiviewcontroller *)primaryviewcontroller {     if ([secondaryviewcontroller iskindofclass:[uinavigationcontroller class]] && [[(uinavigationcontroller *)secondaryviewcontroller topviewcontroller] iskindofclass:[detailviewcontroller class]] && ([(detailviewcontroller *)[(uinavigationcontroller *)secondaryviewcontroller topviewcontroller] detailitem] == nil)) {         // return yes indicate have handled collapse doing nothing; secondary controller discarded.         return yes;     } else {         return no;     } }  - (uiviewcontroller *)splitviewcontroller:(uisplitviewcontroller *)splitviewcontroller separatesecondaryviewcontrollerfromprimaryviewcontroller:(uiviewcontroller *)primaryviewcontroller{      if ([primaryviewcontroller iskindofclass:[uinavigationcontroller class]]) {         (uiviewcontroller *controller in [(uinavigationcontroller *)primaryviewcontroller viewcontrollers]) {             if ([controller iskindofclass:[uinavigationcontroller class]] && [[(uinavigationcontroller *)controller visibleviewcontroller] iskindofclass:[noteviewcontroller class]]) {                 return controller;             }         }     }      // no detail view present     uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil];     uinavigationcontroller *detailview = [storyboard instantiateviewcontrollerwithidentifier:@"detailview"];      // ensure button enabled     uiviewcontroller *controller = [detailview visibleviewcontroller];     controller.navigationitem.leftbarbuttonitem = self.splitviewcontroller.displaymodebuttonitem;     controller.navigationitem.leftitemssupplementbackbutton = yes;      return detailview;  } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -