Hi I have a modalview controller that pops up on the main menu after the user successfully logs in. This is used for additional roles that needs to be saved on the userdefaults. The modal gets dismissed properly but it doesn't go through the -viewdidappear method after. I had it programmed so that after choosing the role, it would load the whole main menu with populated data based off of the role. I used to do a "presentViewController:roleVC" instead of the modal but decided not to use it anymore as I cannot modify the size of the VC (I want it to display with a modal style). Anyway, with presentViewController, the parent VC goes through the -viewdidappear which works perfectly for me before. Now I'm not sure how to force it to go through the viewdidappear again after dismissing the modal.
Here's some screens to make it more understandable.
This is what's inside my viewdidappear of that 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 you can see, the segue gets pushed after a role is assigned.
This is the dismiss when a button is clicked
- (IBAction)btnRole1:(id)sender {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:2 forKey:@"role"];
[self dismissViewControllerAnimated:YES completion:nil];
}
When this button gets clicked before (using presentviewcontroller), it would go through the viewdidappear. Now it doesn't. Any advice on how to deal with this? I'm pretty new so it's all messy, so any advice on what the best practice is on dealing with this is appreaciated as well.
Thanks!
EDIT: Also, to make it clear, when I was doing a presentViewController without editing its modalproperties (eg. roleVC.modalPresentationStyle = UIModalPresentationFormSheet;) it would dismiss the VC and then would go through the viewdidappear. This is how I called it before and it would hit the viewdidappear after i dismiss it.
UIViewController *roleVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDRoleViewController"];
[self presentViewController:roleVC animated:YES completion:^{}];
UPDATE: So I tried putting a protocol (delegate) on the popup. My problem is this tho, it works perfectly if it's trying to call a segue so it can replace teh detail view. But, I want to have something completely different on top of the Splitviewcontroller so I would call a presentViewcontroller. It wouldn't show up.
here's my code.
This is the modal VC (role controller)
@protocol RoleViewDelegate<NSObject>
-(void)dismissVC;
@end
@interface RoleViewVC : UIViewController
@property(nonatomic, strong) id roleViewDelegate;
on the implementation of the VC
-(IBAction)role1:(id)sender{
if(roleViewDelegate != nil){
[roleViewDelegate dismissVC];
}
}
on the VC that calls them
-(void)dismissVC{
[self dismissViewControllerAnimated:YES completion:nil];
UISToryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
// pop up another VC that contains tabbed menus to replace Split View
AdminMenuViewController *adminVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDAdminVC"];
[self presentViewController:adminVC animated:YES completion:nil]
}