cocoa touch - ipad modalviewcontroller when dismissed does not go to the viewdidappear of the mainviewcontroller -
hi have modalview controller pops on main menu after user logs in. used additional roles needs saved on userdefaults. modal gets dismissed doesn't go through -viewdidappear method after. had programmed after choosing role, load whole main menu populated data based off of role. used "presentviewcontroller:rolevc" instead of modal decided not use anymore cannot modify size of vc (i want display modal style). anyway, presentviewcontroller, parent vc goes through -viewdidappear works me before. i'm not sure how force go through viewdidappear again after dismissing modal.
here's screens make more understandable.
this what's inside viewdidappear of main menu. (....will direct traffic vc)
if([[nsuserdefaults standarduserdefaults] objectforkey:@"role"] == nil){ /*uiviewcontroller *rolevc = [storyboard instantiateviewcontrollerwithidentifier:@"sbidroleviewcontroller"]; [self presentviewcontroller:rolevc animated:yes completion:^{}];*/ uiviewcontroller *rolevc = [storyboard instantiateviewcontrollerwithidentifier:@"sbidroleviewcontroller"]; rolevc.modalpresentationstyle = uimodalpresentationformsheet; rolevc.modaltransitionstyle = uimodaltransitionstylecrossdissolve; [self presentviewcontroller:rolevc animated:yes completion:nil]; rolevc.view.superview.autoresizingmask = uiviewautoresizingflexibletopmargin | uiviewautoresizingflexiblebottommargin; rolevc.view.superview.bounds = cgrectmake(0, 0, 500, 600); }else{ if([[nsuserdefaults standarduserdefaults] integerforkey:@"role"] == 1){ mainadmindashboardviewcontroller *adminvc = (mainadmindashboardviewcontroller *)[self.storyboard instantiateviewcontrollerwithidentifier:@"mainadmindashboardviewcontrollerid"]; [self presentviewcontroller:adminvc animated:no completion:nil]; }else{ [self performseguewithidentifier:@"seguepushtomatsfromswitchboard" sender:self]; } }
as can see, segue gets pushed after role assigned.
this dismiss when button clicked
- (ibaction)btnrole1:(id)sender { nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; [prefs setinteger:2 forkey:@"role"]; [self dismissviewcontrolleranimated:yes completion:nil]; }
when button gets clicked before (using presentviewcontroller), go through viewdidappear. doesn't. advice on how deal this? i'm pretty new it's messy, advice on best practice on dealing appreaciated well.
thanks!
edit: also, make clear, when doing presentviewcontroller without editing modalproperties (eg. rolevc.modalpresentationstyle = uimodalpresentationformsheet;) dismiss vc , go through viewdidappear. how called before , hit viewdidappear after dismiss it.
uiviewcontroller *rolevc = [storyboard instantiateviewcontrollerwithidentifier:@"sbidroleviewcontroller"]; [self presentviewcontroller:rolevc animated:yes completion:^{}];
update: tried putting protocol (delegate) on popup. problem tho, works if it's trying call segue can replace teh detail view. but, want have different on top of splitviewcontroller call presentviewcontroller. wouldn't show up.
here's code.
this modal vc (role controller)
@protocol roleviewdelegate<nsobject> -(void)dismissvc; @end @interface roleviewvc : uiviewcontroller @property(nonatomic, strong) id roleviewdelegate;
on implementation of vc
-(ibaction)role1:(id)sender{ if(roleviewdelegate != nil){ [roleviewdelegate dismissvc]; } }
on vc calls them
-(void)dismissvc{ [self dismissviewcontrolleranimated:yes completion:nil]; uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil]; // pop vc contains tabbed menus replace split view adminmenuviewcontroller *adminvc = [storyboard instantiateviewcontrollerwithidentifier:@"sbidadminvc"]; [self presentviewcontroller:adminvc animated:yes completion:nil] }
for might having same issues when popping viewcontrollers , needs else after dismissing, solved using this
https://stackoverflow.com/a/7194182/639713
basically, place delay, reason it's taking modalviewcontroller removed. added delegate call method delay happens.
Comments
Post a Comment