2013-04-10 111 views
4

我已經爲我的應用程序編寫了一個自定義塞格,它部分遮蔽了源視圖控制器。賽格工作正常,我得到了預期的效果。當我按下按鈕將segue展開回源控制器時,應用程序崩潰。我用各種方法寫了一些日誌語句,但沒有任何東西被調用,所以我認爲我錯誤地將意見連接起來了。這裏的賽格代碼:自定義塞恩後退按鈕崩潰應用程序

- (void)perform { 
NSLog(@"performing!"); 
UIView *sourceView = ((UIViewController *)self.sourceViewController).view; 
UIView *destView = ((UIViewController *)self.destinationViewController).view; 
UIViewController *sourceController = ((UIViewController *)self.sourceViewController); 

if (!_rewinding) { 
[sourceView.window insertSubview:destView aboveSubview:sourceView]; 
    destView.center = CGPointMake(sourceView.frame.size.width * 1.5, sourceView.center.y); 
} 

CGPoint newSourceCenter = CGPointMake(sourceView.frame.origin.x - sourceView.frame.size.width * 0.4, sourceView.center.y); 
CGPoint newDestCenter = CGPointMake(sourceView.center.x + sourceView.frame.size.width * 0.1, sourceView.center.y); 


[UIView animateWithDuration:1.4 
       animations:^{ 
        if (_rewinding) { 
         NSLog(@"rewind in segu"); 
         destView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, destView.center.y); 
         sourceView.center = CGPointMake([UIScreen mainScreen].bounds.size.width*1.5, sourceView.center.y); 
         destView.alpha = 1.0; 
        } else { 
         destView.center = newDestCenter; 
         sourceView.center = newSourceCenter; 
         sourceView.alpha = 0.5; 
        } 
       } completion:^(BOOL finished) { 
        if (_rewinding) 
        NSLog(@"completed animation"); 
       }]; 
} 

一對夫婦的照片,以顯示發生了什麼。在點擊單元格時,詳細視圖從右側的屏幕向外滑動,並且源視圖幻燈片也向左滑動。

main/source viewafter segue

我使用[source presentViewController:dest]但這樣做,試圖消除從窗口源視圖。由於我部分模糊了源,因此必須在動畫之後保留在屏幕上。什麼是正確的方法來設置?

編輯: 隨着殭屍的啓用,我在日誌中得到了這個。這對應於destinationViewController。所以很明顯它在賽季中沒有被保留。

[58880:c07] *** -[UIStoryboardUnwindSegueTemplate performSelector:withObject:withObject:]: message sent to deallocated instance 0x1f3c7fe0 
+0

什麼是確切的崩潰?你可以發佈符號化的崩潰日誌嗎? – 2013-04-10 16:58:11

+0

@RoboticCat崩潰可能不是正確的用詞。我得到一個EXC_BAD_ACCESS。我正在研究發生的事情。 – brodney 2013-04-10 17:11:03

+0

要清楚:您是說0x1f3c7fe0對應於您打開的前一個視圖控制器實例?如果一個視圖控制器被釋放,我會感到驚訝,但如果是這樣的話,我不知道如何尋找這個bug。 – 2013-04-10 17:59:25

回答

1

我會與我落得這樣做回答這個問題,但離開它打開,因爲我的方式做到這一點離開屏幕上的原始視圖的一部分SEGUE認真感興趣。

我的快速解決方案是在原始視圖控制器中處理所有動畫。我認爲這涵蓋了上述與內存有關的所有問題,但它可能不正確,所以請自擔風險使用。

- (void)showModalDetailView { 
NSLog(@"show modal"); 
if (!self.detailViewController) { 
    self.detailViewController = (SegmentDetailViewController *)[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"segDetail"]; 
    self.detailViewController.view.center = CGPointMake(self.view.frame.size.width * 1.5, self.view.center.y); 
    [self.view.superview addSubview:self.detailViewController.view]; 
    self.detailViewController.delegate = self; 
} 

CGPoint newSourceCenter = CGPointMake(self.view.frame.origin.x - self.view.frame.size.width * 0.4, self.view.center.y); 
CGPoint newDestCenter = CGPointMake(self.view.center.x + self.view.frame.size.width * 0.1, self.view.center.y); 

[UIView animateWithDuration:1.4 
       animations:^{ 
        if (self.shouldRewind) { 
         self.view.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.view.center.y); 
         self.detailViewController.view.center = CGPointMake([UIScreen mainScreen].bounds.size.width*1.5, self.detailViewController.view.center.y); 
         self.view.alpha = 1.0; 
         self.shouldRewind = NO; 
         self.detailViewController = nil; 
        } else { 
         self.detailViewController.view.center = newDestCenter; 
         self.view.center = newSourceCenter; 
         self.view.alpha = 0.5; 
         self.shouldRewind = YES; 
        } 
       } completion:^(BOOL finished) { 
        NSLog(@"animation complete"); 

       }]; 

} 
相關問題