gpt4 book ai didi

ios - DismissViewControllerAnimated EXC_Bad_ACCESS 为真

转载 作者:搜寻专家 更新时间:2023-10-31 21:58:37 24 4
gpt4 key购买 nike

我正在按照苹果从 WWDC 发布的教程“查看 View Controller 内部”进行操作,以创建自定义 View Controller (此处为视频:https://developer.apple.com/videos/wwdc/2014/,示例代码为:https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html)。我主要是复制他们的 objective-C 并将其逐行翻译成 Swift,除了用手势点击隐藏覆盖 viewController 之外,我几乎已经开始工作了。

当我打电话时:

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

我得到一个错误:Thread 1: EXC_BAD_ACCESS (code=1, address=0xc) if the animated field set to true。如果将其设置为 false,则一切正常,并且在没有动画的情况下消失)。另一件奇怪的事情是它有时会在设置为 true 时起作用。也许每 15 次尝试中就有一次动画会完成并且我不会收到错误。

我遵循与示例代码中定义的完全相同的结构,其中有一个转换委托(delegate)处理演示 Controller 对象和动画的创建。

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
}

}

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

最佳答案

确保您的过渡代表被牢牢捕获。将其设置为 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];

关于ios - DismissViewControllerAnimated EXC_Bad_ACCESS 为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25919551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com