DismissViewControllerAnimated EXC_Bad_ACCESS 为 true [英] DismissViewControllerAnimated EXC_Bad_ACCESS on true

查看:20
本文介绍了DismissViewControllerAnimated EXC_Bad_ACCESS 为 true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Apple 从 WWDC 发布的用于创建自定义视图控制器的教程查看内部视图控制器"(视频在这里:https://developer.apple.com/videos/wwdc/2014/ 和此处的示例代码:https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html).我主要是复制他们的 Objective-C 并将其逐行翻译成 Swift,除了用手势点击隐藏覆盖视图控制器之外,我几乎让它工作了.

I was following the tutorial "A look inside View Controllers" posted from WWDC by apple for creating custom view controllers (video here: https://developer.apple.com/videos/wwdc/2014/ and sample code here: https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html). I've been mostly copying over their objective-C and translating it into Swift line by line and I've almost got it working except for hiding the overlay viewController with a gesture tap.

当我打电话时:

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

如果动画字段设置为 true,则出现错误:线程 1:EXC_BAD_ACCESS (code=1, address=0xc).如果将其设置为 false,则一切正常,并且在没有动画的情况下消失).另一个奇怪的事情是它有时会在设置为 true 时起作用.也许每 15 次尝试就有一次动画会完成,我不会出错.

I get an error: Thread 1: EXC_BAD_ACCESS (code=1, address=0xc) if the animated field is set to true. If it is set to false everything works perfectly fine and it disappears without animation). Another weird thing is it will sometimes work when set to true. Maybe once out of every 15 attempts the animation will complete and I won't get an error.

我遵循与示例代码中定义的完全相同的结构,使用一个过渡委托来处理呈现控制器对象的创建以及动画.

I'm following the exact same structure as defined in the sample code with a transitioning delegate handling the creation of the presentation controller object as well as the animations.

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
}

}

我知道有一些与此相关的问题,但在阅读这些问题后,我仍然感到困惑,正在寻求帮助.

I know there have been a few questions out there regarding this but after reading them I'm still stumped and am looking for assistance.

推荐答案

确保您的过渡委托得到有力支持.将其设置为控制器上的强属性.

Make sure your transitioning delegate is held strongly. Set it as a strong property on your controller.

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];

这篇关于DismissViewControllerAnimated EXC_Bad_ACCESS 为 true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆