1

I use custom UIPresentationController to perform sequel with my own animation. In prepareForSegue:

myDestinationController.transitioningDelegate = DBViewControllerTransitioningDelegate()
myDestinationController.modalPresentationStyle = .Custom

This is mine DBViewControllerTransitioningDelegate:

class DBViewControllerTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {

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

    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return DBTransitioningAnimator()
    }
}

It is not working, because the methods are not called. But when I set:

myDestinationController.transitioningDelegate = self

and within my self controller add 2 methods from my DBViewControllerTransitioningDelegate everything is fine. These two methods are called. Why? What is the difference?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

3

Declaration for transitioningDelegate in UIViewController:

weak var transitioningDelegate: UIViewControllerTransitioningDelegate?

As you can see transitioningDelegate holding a weak reference. The custom TransitioningDelegate instance got released right after you created it since no one have the ownership here. When you adopt the delegate in the "controller" and assign it to transitioningDelegate 'someone' is keeping this delegate instance for you.

Community
  • 1
  • 1
trgoofi
  • 3,091
  • 3
  • 16
  • 11