Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone dismissModalViewControllerAnimated:(和dismissViewControllerAnimated)在iOS 5中崩溃_Iphone_Uiviewcontroller_Ios5_Dismiss - Fatal编程技术网

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

Iphone dismissModalViewControllerAnimated:(和dismissViewControllerAnimated)在iOS 5中崩溃,iphone,uiviewcontroller,ios5,dismiss,Iphone,Uiviewcontroller,Ios5,Dismiss,我找不到任何合乎逻辑的解释,但事实是,在iOS 5(xCode 4.2)中,如果我呈现ModalView:*动画:是的,我可以调用DismissModalViewWanimated:*很好,但如果我调用presentModalView:*动画:否,则调用Dismise方法会崩溃。(如果使用新的presentViewController:animated:completion:+dismissViewControllerAnimated:,效果相同)。我现在正试图解决这个问题(我不想让演示动画化)

我找不到任何合乎逻辑的解释,但事实是,在iOS 5(xCode 4.2)中,如果我呈现ModalView:*动画:是的,我可以调用DismissModalViewWanimated:*很好,但如果我调用presentModalView:*动画:否,则调用Dismise方法会崩溃。(如果使用新的presentViewController:animated:completion:+dismissViewControllerAnimated:,效果相同)。我现在正试图解决这个问题(我不想让演示动画化),并向苹果报告一个bug,但我已经为此绞尽脑汁了一段时间。欢迎提出任何建议。在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_访问:

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中,应用程序: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];  
}
- (IBAction)closeLoginWindow {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CloseLoginWindow" object:nil];
}   //doing it this way because calling on the self.parentViewController doesn't work
- (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
}    
在loginController中:

- (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];  
}
- (IBAction)closeLoginWindow {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CloseLoginWindow" object:nil];
}   //doing it this way because calling on the self.parentViewController doesn't work
- (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
}    
回到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];  
}
- (IBAction)closeLoginWindow {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CloseLoginWindow" object:nil];
}   //doing it this way because calling on the self.parentViewController doesn't work
- (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中,生命周期的管理发生了某种变化,我无法详细解释这个问题。无论如何,解决方法是将工作流从ApplicationIDFinishLaunchingWithOptions推迟到ApplicationIDBecomeActive。在调用ApplicationIDFinishLaunchingWithOptions时,似乎有些东西没有正确初始化

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

好奇你的反馈:)…

我会加上我的2美分:我有ImagePickerController,只有在我没有手动释放picker(IOS 5 SDK)的情况下,它才能被解除

所以。对于您的情况,我可以提供以下解决方法: 1.删除行-[loginController release]; 2.要防止内存泄漏,请将loginController作为属性添加到当前控制器,并仅在当前控制器的dealloc()中释放它:

@interface myViewController : UIViewController 

@property (nonatomic, retain) LoginController *loginController;

@end

...

@implementation myViewController

- (void)showLoginPanel {    
    self.loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
     // ... something goes here  
}

-(IBAction)loginClose() 
{
    // this should close all windows as far as you call it from current (main) controller
    [self dismissModalViewControllerAnimated:YES]; 
    // ... then anything you want EXCEPT [loginController release];
}

-(void)dealloc() 
{
    [loginController release];
}

@end
祝你好运:)


另外,我刚刚写了这篇文章,所以这只是一个如何欺骗它的想法。也许有人会纠正我。。。尽管无论如何它对我有效。

正如我所怀疑的,从loginController的viewDidLoad方法中删除动画与此问题无关。在这里抓救命稻草,真奇怪。您确定没有在[loginController release]之外的任何地方释放loginController吗?我会检查以确定,但是更改动画标志并保持所有其他代码不变会导致崩溃。我认为不管动画如何,管理问题都会出现,但目前还无法解释,所以我一定会检查。@Manali,还有其他方法可以实例化该类,但在崩溃时不存在。我将编辑我的帖子以显示确切的流程。只需输入一个NSLog来检查可能会释放视图的内存不足警告,我没有警告,也没有出现日志。看起来我不必像我所想的那样通过并将所有presentModalViewController调用更改为presentViewController调用。嗯,我可以把它保存到下一个版本。我也有同样的问题,只是把它移到了DidBecomeActive并提交了修复程序,以便在商店里有一个无bug的版本。。。不知道苹果的生命周期发生了什么变化……这对我没有帮助:我打开了showLoginPanel(iAction),登录关闭作为回调,但在主线程中,logincontroller仅在dealloc中松弛,我有crach: