当被解雇时,ipad modalviewcontroller不会转到mainviewcontroller的viewdidappear [英] ipad modalviewcontroller when dismissed does not go to the viewdidappear of the mainviewcontroller

查看:124
本文介绍了当被解雇时,ipad modalviewcontroller不会转到mainviewcontroller的viewdidappear的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在用户成功登录后会在主菜单上弹出一个模态视图控制器。这用于需要保存在用户默认设置上的其他角色。模态被正确解散,但之后不会通过-viewdidappear方法。我对它进行了编程,以便在选择角色后,它会根据角色加载整个主菜单和填充数据。我曾经做过presentViewController:roleVC而不是模态,但决定不再使用它,因为我无法修改VC的大小(我希望它以模态样式显示)。无论如何,使用presentViewController,父VC通过-viewdidappear,这对我来说非常适合。现在我不确定在解雇模态后如何强制它再次通过viewdidappear。

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.

这是我的viewdid出现在主菜单中的内容。 (....将直接交通VC)

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];
        }
    }

正如你所看到的,segue被推后了角色已分配。

As you can see, the segue gets pushed after a role is assigned.

这是点击按钮时的解雇

- (IBAction)btnRole1:(id)sender {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setInteger:2 forKey:@"role"];
    [self dismissViewControllerAnimated:YES completion:nil];
}

当此按钮被点击之前(使用presentviewcontroller),它将通过viewdidappear。现在它没有。关于如何处理这个问题的任何建议?我很新,所以这一切都很混乱,所以关于处理这个问题的最佳做法的任何建议都是适用的。

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.

谢谢!

编辑:
此外,为了清楚起见,我在做一个 presentViewController 时没有编辑其modalproperties(例如。 roleVC.modalPresentationStyle = UIModalPresentationFormSheet;)它将关闭VC然后将通过viewdidappear。
这是我之前调用它的方式,它会在我解除它后点击viewdidappear。

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:^{}];

更新:
所以我尝试了一个协议(委托) )弹出窗口。我的问题是这个,如果它试图调用一个segue它可以取代细节视图,它的效果很好。但是,我希望在Splitviewcontroller之上有一些完全不同的东西,所以我会调用presentViewcontroller。它不会出现。

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.

这是我的代码。

这是模态VC(角色控制器)

This is the modal VC (role controller)

@protocol RoleViewDelegate<NSObject>
-(void)dismissVC;
@end
@interface RoleViewVC : UIViewController
@property(nonatomic, strong) id roleViewDelegate;

执行VC

-(IBAction)role1:(id)sender{
   if(roleViewDelegate != nil){
       [roleViewDelegate dismissVC];
   }
}

调用它们的VC上的

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]
}


推荐答案

对于那些在弹出viewcontrollers时可能遇到同样问题并且在解雇后需要做其他事情的人,我用这个解决了它

For those who might be having the same issues when popping up viewcontrollers and needs to do something else after dismissing, I solved it using this

https://stackoverflow.com/a/7194182/639713

基本上,放置一个延迟,因为某些原因它需要一些东西来移除modalviewcontroller。我添加了一个委托,它将调用另一个延迟发生的方法。

Basically, place a delay, as for some reason it's taking some for the modalviewcontroller to be removed. I added a delegate that will call another method which the delay happens.

这篇关于当被解雇时,ipad modalviewcontroller不会转到mainviewcontroller的viewdidappear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆