gpt4 book ai didi

iphone - 解雇ModalViewControllerAnimated : (and dismissViewControllerAnimated) crashing in iOS 5

转载 作者:行者123 更新时间:2023-12-03 18:33:02 25 4
gpt4 key购买 nike

我找不到任何合乎逻辑的解释,但事实仍然是,在iOS 5(xCode 4.2)中,如果我presentModalView:*animated:YES,我可以调用dismissModalViewAnimated:*很好,但如果我调用presentModalView:* animated:NO,则调用dismiss方法会崩溃。 (如果我使用新的presentViewController:animated:completion:+missViewControllerAnimated:效果相同)。我现在打算尝试解决这个问题(我不想让演示文稿动画化)并向苹果报告错误,但我已经为此苦恼了一段时间。欢迎任何和所有建议。 iOS 5 上的内容不多,所以请尽可能提供帮助。在 iOS 4 或 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:

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

注意一点:我在 loginController 中有一个动画,它发生在 viewDidLoad 上。看看去掉它是否会改变什么,但我想把它拿出来,因为我需要尽快找到解决方案。

<小时/>

[编辑]完整代码流程...在 AppDelegate 中,application:didFinishLaunchingWithOptions:

if (!loggedIn)  [myViewController showLoginPanel];

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

在登录 Controller 中:

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

返回 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 时正确初始化。

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

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

关于iphone - 解雇ModalViewControllerAnimated : (and dismissViewControllerAnimated) crashing in iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7821617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com