dismissModalViewControllerAnimated :(和dismissViewControllerAnimated)在iOS 5中崩溃

jbc*_*man 9 iphone uiviewcontroller dismiss ios5

我找不到任何合理的解释,但事实仍然是,在iOS 5(xCode 4.2)中,如果我presentModalView:*animated:YES,我可以调用dismissModalViewAnimated:*很好,但如果我调用presentModalView:*animated:NO ,然后调用dismiss方法崩溃.(如果我使用新的presentViewController,它的工作原理相同:animated:completion:+ dismissViewControllerAnimated :).我现在正在尝试解决这个问题(我不希望演示文稿动画)并向Apple报告一个错误,但我已经打了一段时间.欢迎任何和所有建议.在iOS 5上没有多少,所以请尽可能帮助.在iOS 4或iOS 5中不会崩溃的示例代码:

LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
[self presentModalViewController:loginController animated:YES];
[loginController release];
...
[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

这将在解雇调用中在iOS 5中使用EXC_BAD_ACCESS崩溃:

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

一个注意事项:我在loginController中有一个动画,它发生在viewDidLoad上.去看看是否会改变任何东西,但我想把它拿出去,因为我需要一个解决方案尽快.


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

if (!loggedIn)  [myViewController showLoginPanel];
Run Code Online (Sandbox Code Playgroud)

在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];  
}
Run Code Online (Sandbox Code Playgroud)

在loginController中:

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

回到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
}    
Run Code Online (Sandbox Code Playgroud)

Ren*_*lin 4

在 iOS5 中,生命周期的管理发生了某种变化,我无法详细解释这个问题。无论如何,修复方法是将工作流程从 applicationDidFinishLaunchingWithOptions 推迟到 applicationDidBecomeActive。似乎有些东西没有在调用 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]
    }
}
Run Code Online (Sandbox Code Playgroud)

很好奇你的反馈:)....