dismissModalViewControllerAnimated :(和dismissViewControllerAnimated)在iOS 5中崩溃 [英] dismissModalViewControllerAnimated: (and dismissViewControllerAnimated) crashing in iOS 5

查看:99
本文介绍了dismissModalViewControllerAnimated :(和dismissViewControllerAnimated)在iOS 5中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何合乎逻辑的解释,但事实仍然是,在iOS 5(xCode 4.2)中,如果我presentModalView:* animated:YES,我可以调用dismissModalViewAnimated:*很好,但是如果我调用presentModalView:*动画:不,然后调用dismiss方法崩溃。 (如果我使用新的presentViewController,它的工作原理相同:animated:completion:+ dismissViewControllerAnimated :)。我现在要尝试解决这个问题(我不想让演示文稿变得生气勃勃)并向Apple报告一个错误,但我一直在打扰这个问题。欢迎任何和所有建议。在iOS 5上没有多少,所以请尽可能帮助。在iOS 4或iOS 5中不崩溃的示例代码:

I can't find any logical explanation, but the fact remains that, in iOS 5 (xCode 4.2), if I presentModalView:* animated:YES, I can call dismissModalViewAnimated:* fine, but if I call presentModalView:* animated:NO, then calling the dismiss method crashes. (This works the same if I use the new presentViewController:animated:completion: + dismissViewControllerAnimated:). I am going TRY to work around this for now (I don't want the presentation animated) and report a bug to Apple, but I have been beating my head on this for a while. Any and all suggestions are welcome. Not much out there on iOS 5, so please help if you can. Sample code that does not crash in iOS 4 or iOS 5:

LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
[self presentModalViewController:loginController animated:YES];
[loginController release];
...
[self dismissModalViewControllerAnimated:YES];

在解雇电话中,这将在iOS 5中以EXC_BAD_ACCESS崩溃:

This will crash in iOS 5 with EXC_BAD_ACCESS on the dismiss call:

LoginController *loginController = [[LoginController alloc]    initWithNibName:@"LoginControllerGG" bundle:nil];
[self presentModalViewController:loginController animated:NO];
[loginController release];
...
[self dismissModalViewControllerAnimated:YES]; //crashes with EXC_BAD _ACCESS

注意:我在loginDtroller中有一个动画,发生在viewDidLoad上。去看看是否采取了改变任何东西,但我希望得到这个,因为我需要一个解决方案尽快。

One note: I have an animation within the loginController that happens on viewDidLoad. Going to see if taking that out changes anything, but I wanted to get this out there since I need a solution asap.

完整的代码流程...在AppDelegate中,应用程序:didFinishLaunchingWithOptions:

Full code flow... In AppDelegate, application:didFinishLaunchingWithOptions:

if (!loggedIn)  [myViewController showLoginPanel];

在myViewController中:

In myViewController:

- (void)showLoginPanel {    
    LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
    if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
        [self presentViewController:loginController animated:NO completion:nil];
    } else {
        [self presentModalViewController:loginController animated:NO]; //iOS 4 works fine with or without animation   
    } 
    [loginController release];  
}

在loginController中:

In loginController:

- (IBAction)closeLoginWindow {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CloseLoginWindow" object:nil];
}   //doing it this way because calling on the self.parentViewController doesn't work

返回myViewController:

Back in myViewController:

- (void) viewDidLoad
    ...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeLoginWindow) name:@"CloseLoginWindow" object:nil];
    ...

- (void)closeLoginWindow {
    if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
        [self dismissViewControllerAnimated:YES completion:nil];    //iOS 5 crashes only if presentation was not animated
    } else [self dismissModalViewControllerAnimated:YES];    //deleting the previous condition, iOS 5 still crashes if presentation was not animated
}    


推荐答案

在iOS5中,生命周期的管理有所改变,我无法详细解释这个问题。无论如何,修复是将该工作流从applicationDidFinishLaunchingWithOptions推迟到applicationDidBecomeActive。似乎在applicationDidFinishLaunchingWithOptions调用时没有初始化某些内容。

In iOS5 the managing of the lifecyle somehow changed and I cannot explain that issue in detail. Anyway, the fix is to postpone that workflow from applicationDidFinishLaunchingWithOptions to applicationDidBecomeActive. It seems that something isn't initialized right at the call of applicationDidFinishLaunchingWithOptions.

- (void)applicationDidFinishLaunchingWithOptions:... {    
    // in order to do this only at launching, but not on every activation 
    // Declaration as property for example
    applicationDidLaunch = YES;
}

- (void) applicationDidBecomeActive:(UIApplication *)application {
    if (applicationDidLaunch) {
        applicationDidLaunch = NO;
        [Start your login Workflow with modal view presenting here]
    }
}

对您的反馈很好奇:)....

Curious to ur feedback :)....

这篇关于dismissModalViewControllerAnimated :(和dismissViewControllerAnimated)在iOS 5中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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