2015-08-28 50 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]; 

現在,當我改變了它的一切就像一個魅力。希望它能幫助別人。