2015-08-28 49 views
0

我需要实现可堆叠多达三次,放松背部通过全堆到根视图控制器的自定义塞格斯。崩溃而展开,从多个自定义根控制器塞格斯

这里是我的代码赛格瑞:

- (void)perform { 

    UIViewController* sourceViewController = self.sourceViewController; 

    UIView* firstVCView = [(UIViewController*)self.sourceViewController view]; 
    UIView* secondVCView = [(UIViewController*)self.destinationViewController view]; 

    // Get the screen width and height. 
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; 

    // Specify the initial position of the destination view. 
    secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight); 

    // Access the app's key window and insert the destination view above the current (source) one. 
    UIWindow* window = [UIApplication sharedApplication].keyWindow; 

    [window insertSubview:secondVCView aboveSubview:firstVCView]; 

    [UIView animateWithDuration:0.5 animations:^{ 
     firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0); 
     secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0); 
    } completion:^(BOOL finished) { 
     [sourceViewController.navigationController presentViewController:self.destinationViewController animated:NO completion:nil]; 
    }]; 
} 

而对于开卷赛格瑞:

- (void)perform { 

    UIViewController* sourceViewController = self.sourceViewController; 

    UIView* secondView = [(UIViewController*)self.sourceViewController view]; 
    UIView* firstView = [(UIViewController*)self.destinationViewController view]; 

    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 

    UIWindow* window = [UIApplication sharedApplication].keyWindow; 

    [window insertSubview:firstView aboveSubview:secondView]; 

    [UIView animateWithDuration:0.5 animations:^{ 
     firstView.frame = CGRectOffset(firstView.frame, screenWidth, 0); 
     secondView.frame = CGRectOffset(secondView.frame, screenWidth, 0); 
    } completion:^(BOOL finished) { 
     [sourceViewController.navigationController dismissViewControllerAnimated:NO completion:nil]; 

    }]; 
} 

一切正常单过渡 - 我可以很容易地向前走,并放松背部为好。 但是当我做了两个或更多的过渡,尽量放松背部事后以下错误发生时,右推我与开卷赛格瑞关联的任何代码调用甚至在按钮:

2015-08-28 18:40:37.460 ProjectName[17807:973012] *** -[UIStoryboardUnwindSegueTemplate performSelector:withObject:withObject:]: message sent to deallocated instance 0x7fbd4bc717d0 

显然它的最后一个控制器丢失。 但是,如果我将其锁定,并在内存控制器的整个前一个堆栈,然后什么也没有发生,除了方法调用“prepareForSegue”:没有其他委托方法调用,没有抛出异常,不进行过渡。 此外,当所有控制器锁定在内存中,我试图调用popToRootViewControllerAnimated和其他类似的方法 - 根本没有结果。

我跑出去的想法如何解决它,并阅读整个互联网的解决方案。我该如何解决它?

回答

0

麻烦的是,在这条线的定制SEGUE:

[sourceViewController.navigationController presentViewController:self.destinationViewController animated:NO completion:nil]; 

我应该pushViewController代替presentViewController:

[sourceViewController.navigationController pushViewController:self.destinationViewController animated:NO]; 

现在,当我改变了它的一切就像一个魅力。希望它能帮助别人。