objective c - UIViewController loading a UISplitViewController -
i have uinavigationcontroller rootviewcontroller, contains uiviewcontroller (which call projects sake of discussion). in projects, have button, when clicked, want load uisplitviewcontroller - preferably sliding bottom, although nice-to-have feature.
in uisplitviewcontroller, have "close" button want remove uisplitviewcontroller re-showing projects.
from have read, uisplitviewcontrollers must rootviewcontrollers. in mind, code far follows.
appdelegate
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; ... // load projects panel root view controller window projectslistviewcontroller *projects = [[projectslistviewcontroller alloc] init]; navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:projects]; [window setrootviewcontroller:navigationcontroller]; [window makekeyandvisible]; return yes; } projectsviewcontroller
-(ibaction)loaddetails { projectnavigationcontroller *projectnavpanel = [[projectnavigationcontroller alloc] init]; projectdetailcontroller *projectdetailpanel = [[projectdetailcontroller alloc] init]; projectsplitviewcontroller *splitrootcontroller = [[projectsplitviewcontroller alloc] init]; [splitrootcontroller setviewcontrollers:[nsarray arraywithobjects:projectnavpanel, projectdetailpanel, nil]]; [[self view] removefromsuperview]; [[appdelegate window] setrootviewcontroller:splitrootcontroller]; } uisplitviewcontroller naviagaion
- (void)loadprojects { // load projects list view projectslistviewcontroller *projectslist = [[projectslistviewcontroller alloc] init]; [[[self parentviewcontroller] view] removefromsuperview]; [[appdelegate window] setrootviewcontroller:projectslist]; } now, know wrong, , unsurprisingly having adverse effects on other methods. in fact, type this, noticed projects page being loaded in navigationcontroller on launch, placed directly on window when splitviewcontroller closed. can me explaining correct method of achieving this?
thanks
apple uisplitviewcontroller must topmost view controller in app, and must there entire lifetime of app. you've noticed, if ignore this, everything can break.
there alternatives out there don't break way, e.g. mgsplitviewcontroller. google around. if have time, cook own implementation of split view controller , in complete control.
if want use apple's uisplitviewcontroller in "crazy" ways, can install root vc (as apple demand), , have @ root time, show other uis modally on top of it. hide modal ui make split view controller appear. nasty , hacky though.
a while asked related question may of interest:
best way switch between uisplitviewcontroller , other view controllers?
Comments
Post a Comment