ios - Clarification on prepareforsegue and presentModalViewController while using Storyboard -
i have app loginviewcontroller initial view.
note: in appdelegate.m, self.window.rootviewcontroller not tabbarcontroller.
after auth, present main part of app, has tabbarcontroller (identifier:tabbar) 2 tabs , 1 tab has navigation controller. using core data, need pass moc.
if use,
uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil]; uitabbarcontroller *obj=[storyboard instantiateviewcontrollerwithidentifier:@"tabbar"]; [obj setselectedindex:0];// tab show first [self presentmodalviewcontroller:obj animated:yes];
it works visually. need pass moc. read preparetosegue method,created segue (modal, not shown in pic) loginvc targetviewcontroller (tabbar>navigationcontroller1>view1), named segue "loginsegue" , used following code:
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { uinavigationcontroller *navcontroller = (uinavigationcontroller *)[segue destinationviewcontroller]; view1 *devicelist = (view1 *)[[navcontroller viewcontrollers] lastobject]; devicelist.managedobjectcontext = managedobjectcontext; }
the tabbar not show. how set tabbar controller in case?
i have been trying grasp on getting reference modal tabbar, still not clear. can 1 explain in layman terms how handle situation this?
i think better use design doesn't use modal transition tab bar controller. modal presentations supposed interruptions normal flow of app, not getting main controller on screen. there 2 alternatives, think better. can leave login controller initial root view controller of window, switch out tab bar controller (which new root view controller of window, , login controller deallocated). works ok, think in case want pass moc app delegate (i presume) controller in tab bar controller, think second way better.
the second way this, , way login controllers, have tab bar controller root view controller of window, , present login controller modally viewdidappear method of initial view (which 1 you're calling view1). if presentation animation set no, login controller first thing user sees:
-(void)viewdidappear:(bool)animated { [super viewdidappear:animated]; static int first = 1; if (first) { loginviewcontroller *login = [self.storyboard instantiateviewcontrollerwithidentifier:@"login"]; [self presentviewcontroller:login animated:no completion:nil]; first = 0; } }
the if statement in there presentation doesn't happen again when come login controller (you more sophisticated having delegate call view1 login controller indicating login successful if want, works).
if login succeeds, dismiss login controller, , you'll there in first view (if fails, never dismiss it, , maybe put message saying login failed).
if go route, can pass moc in app delegate this:
uinavigationcontroller *nav = [(uitabbarcontroller *)self.window.rootviewcontroller viewcontrollers][0]; view1 *devicelist = (view1 *)nav.viewcontrollers.lastobject; devicelist.managedobjectcontext = managedobjectcontext;
Comments
Post a Comment