ipad modalviewcontroller在解除时不会转到主ViewController的ViewDidDisplay
嗨,我有一个modalview控制器,在用户成功登录后会在主菜单上弹出。这用于需要保存在UserDefault上的其他角色。模态会被正确地解除,但之后不会通过-viewdidebeen方法。我对它进行了编程,这样在选择角色后,它将加载整个主菜单,其中包含基于角色的填充数据。我曾经做过一个presentViewController:roleVC而不是模态,但我决定不再使用它,因为我无法修改VC的大小,我希望它以模态样式显示。无论如何,在presentViewController中,父VC会通过-viewdidappear,这对我来说非常适合。现在,我不知道如何强制它通过ViewDidDisplay,在取消模式后再次出现 这里有一些屏幕可以让你更容易理解 这是我的主菜单视图中的内容。。。。你会指挥交通吗ipad modalviewcontroller在解除时不会转到主ViewController的ViewDidDisplay,ipad,cocoa-touch,ios6,modalviewcontroller,presentmodalviewcontroller,Ipad,Cocoa Touch,Ios6,Modalviewcontroller,Presentmodalviewcontroller,嗨,我有一个modalview控制器,在用户成功登录后会在主菜单上弹出。这用于需要保存在UserDefault上的其他角色。模态会被正确地解除,但之后不会通过-viewdidebeen方法。我对它进行了编程,这样在选择角色后,它将加载整个主菜单,其中包含基于角色的填充数据。我曾经做过一个presentViewController:roleVC而不是模态,但我决定不再使用它,因为我无法修改VC的大小,我希望它以模态样式显示。无论如何,在presentViewController中,父VC会通过-v
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之前单击此按钮时,它将通过ViewDidDisplay。现在没有了。关于如何处理这个问题有什么建议吗?我是新来的,所以这一切都很混乱,所以任何关于处理这件事的最佳实践的建议都是值得的
谢谢
编辑:
另外,为了清楚起见,当我在做presentViewController时,没有编辑它的modalProperty,例如:roleVC.modalPresentationStyle=UIModalPresentationFormSheet;它将解散VC,然后通过ViewDidDisplay。
这就是我以前对它的称呼,它会在我关闭它之后出现
UIViewController *roleVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDRoleViewController"];
[self presentViewController:roleVC animated:YES completion:^{}];
更新:
所以我试着在弹出窗口中放置一个协议委托。我的问题是,如果它试图调用一个segue,这样它就可以替换细节视图,那么它工作得非常好。但是,我想在Splitviewcontroller上有一些完全不同的东西,所以我会调用presentViewcontroller。它不会出现
这是我的密码
这是模态VC角色控制器
@protocol RoleViewDelegate<NSObject>
-(void)dismissVC;
@end
@interface RoleViewVC : UIViewController
@property(nonatomic, strong) id roleViewDelegate;
在给他们打电话的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]
}
对于那些在弹出viewcontrollers时可能遇到相同问题,并且在关闭后需要执行其他操作的人,我使用以下方法解决了这些问题 基本上,放置一个延迟,因为出于某种原因,需要一些时间才能移除modalviewcontroller。我添加了一个委托,它将调用发生延迟的另一个方法
-(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]
}