DismissViewControllerAnimated EXC_Bad_ACCESS on true

问题描述:

我正在关注由WWDC发布的WWDC发布的教程“视图控制器内部”,以创建自定义视图控制器(视频位于:https://developer.apple.com/videos/wwdc/2014/和示例代码:https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html)。我一直在复制它们的Objective-C并将它翻译成Swift,并且我几乎可以正常工作,除了用一个手势点击隐藏overlay viewController。DismissViewControllerAnimated EXC_Bad_ACCESS on true

当我打电话:

func dimmingViewTapped(recognizer: UIGestureRecognizer) { 
    self.presentingViewController.dismissViewControllerAnimated(true, completion: nil) 
} 

我得到一个错误:线程1:EXC_BAD_ACCESS(代码= 1,地址= 0xC的),如果动画字段设置为true。如果它设置为false,那么所有的工作都很完美,并且在没有动画的情况下消失)。另一个奇怪的是,它有时会设置为true时工作。也许每15次尝试一次动画就会完成,我不会收到错误。

我遵循与示例代码中定义的完全相同的结构,其中包含处理创建呈现控制器对象以及动画的转换委托。

class OverlayTransitioningDelegate : NSObject, UIViewControllerTransitioningDelegate { 

func presentationControllerForPresentedViewController(presented: UIViewController, 
    presentingViewController presenting: UIViewController, 
    sourceViewController source: UIViewController) -> UIPresentationController { 
     return OverlayPresentationController(presentedViewController: presented, 
      presentingViewController: presenting) 
} 

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    var animationController: OverlayAnimatedTransitioning = OverlayAnimatedTransitioning() 
    animationController.isPresentation = true 
    return animationController 
} 

func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    var animationController: OverlayAnimatedTransitioning = OverlayAnimatedTransitioning() 
    animationController.isPresentation = false 
    return animationController 
} 

} 

我知道已经有几个问题在那里对此但是他们阅读后,我还是住了,正在寻找帮助。

确保您的转换委托保持强大。将其设置为控制器上的强大属性。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
SearchDetailsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"SearchStoryboardID"]; 
viewController.delegate = self; 
SearchDetailsViewControllerTransitioningDelegate *transitioningDelegate = [[SearchDetailsViewControllerTransitioningDelegate alloc] init]; 
**self.detailsTransitioningDelegate** = transitioningDelegate; 
viewController.transitioningDelegate = (id <UIViewControllerTransitioningDelegate>)self.detailsTransitioningDelegate; 
[self presentViewController:viewController animated:YES completion:nil]; 

这是取而代之的评论。 但Swift和Objective-C之间应该没有区别。 两种情况下,TransitioningDelegate都应该很弱。