您好我有一个modalview控制器弹出在主菜单上,用户成功登录后。这用于其他角色,需要保存在userdefaults 。模式被正确解除,但它没有经过-viewdidappear方法。我编写了程序,以便在选择角色后,它会根据角色加载包含填充数据的整个主菜单。我曾经做过“presentViewController:roleVC”而不是模式,但决定不再使用它,因为我无法修改VC的大小(我希望它以模态样式显示)。无论如何,使用presentViewController,父VC会经历-viewdidappear,这对我来说是完美的。现在我不知道如何强制它解散模态后再次通过viewdidappear。ipad modalviewcontroller当解雇不去看viewdidar的主视图控制器
下面是一些屏幕,使其更容易理解。
这就是我的那个主菜单的viewdidappear内。 (....转发流量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];
}
}
正如你所看到的,一个角色分配后SEGUE得到推动。
这是一个按钮被点击
- (IBAction)btnRole1:(id)sender {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:2 forKey:@"role"];
[self dismissViewControllerAnimated:YES completion:nil];
}
时,当该按钮被点击(使用presentviewcontroller)之前,它会经过viewdidappear的解雇。现在它不。有关如何处理此问题的任何建议?我很新,所以它都是混乱的,所以任何关于处理这个问题的最佳实践的建议都是可以理解的。
谢谢!
编辑: 另外,要清楚,当我在做一个presentViewController没有编辑的modalproperties;它将关闭该VC,然后将经过viewdidappear(如roleVC.modalPresentationStyle = UIModalPresentationFormSheet。) 。 这就是我之前调用它的方式,在我解雇它之后它会出现viewdidappear。
UIViewController *roleVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDRoleViewController"];
[self presentViewController:roleVC animated:YES completion:^{}];
UPDATE: 所以我试图把一个协议(委托)上弹出。我的问题是这个寿命,它完美的工作,如果它试图调用一个segue,以便它可以替换细节视图。但是,我希望在Splitviewcontroller上有完全不同的东西,所以我会调用一个presentViewcontroller。它不会出现。
这是我的代码。
这是模式的VC上的VC
-(IBAction)role1:(id)sender{
if(roleViewDelegate != nil){
[roleViewDelegate dismissVC];
}
}
在VC执行调用它们
-(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]
}