1

I have setup a custom transition which is setup similar to this tutorial here.

What I am trying to do now is update a BOOL on the (below) UIViewController. This is the controller that presents the controller on top.

How do I get access/a pointer to the below controller? I have tried self.presentingViewController but this is pointing to a UINavigationController.

Custom Transition Info
The bottom controller is the UIViewControllerTransitioningDelegate. The controllers are linked by a segue. The following is in the prepareForSegue:

self.animationController = [[MESGuessGameTurnZoomAnimation alloc] init];
UIViewController *destVC = segue.destinationViewController;    
destVC.transitioningDelegate = self;

When the destination view controller is presented the user can click Back which simply runs the following (at present) to return to the original view controller:

[self dismissViewControllerAnimated:YES completion:nil];
StuartM
  • 6,743
  • 18
  • 84
  • 160

1 Answers1

1

It sounds like you're trying to pass data back from the presentedVC to the presentingVC. If that's the case, the approach is the same whether you're using the new iOS 7 custom animated transitions or not.

You have 2 options, again the same if you use a standard transition or a custom transition.

  1. Use a delegate pattern when you click Back. That way the presentingVC calls dismiss and can access the presentedVC and any of it's properties.

    How do I set up a simple delegate to communicate between two view controllers?

  2. Use an unwind segue. This accomplishes the same thing but using storyboards. https://developer.apple.com/library/ios/technotes/tn2298/_index.html

You can access both view controllers in prepareForSegue: and in the animationController's animateTransition: method using the transitioningContext but I think you're just talking about transferring back data and that can be done using one of the above approaches.

Community
  • 1
  • 1
Jesse
  • 1,667
  • 12
  • 16
  • Thanks, can you only create an unwind segue for a push segue? Mine is a model with custom transition but dragging a button to the Exit in storyboard doesn't do anything – StuartM Jan 14 '14 at 22:51
  • 1
    You have to create the unwind method in your presenting VC first. Then it will show up when you drag to exit. Signature is `-(IBAction)unwindToViewController:(UIStoryboardSegue *)sender`. Also normally an unwind segue will do the dismiss for you but with custom transitions it doesn't so you'll need to call dismiss in the unwind method. I do this exact thing in my sample code for WWDC Session 218: https://github.com/soleares/SOLPresentingFun. Click on 'Options' which is a model custom transition with an unwind segue. The unwind seque method is at the end of SOLViewController.m. – Jesse Jan 14 '14 at 23:02
  • @Jesse- Thanks for this. When you say 'normally an unwind segue will do the dismiss for you but with custom transitions it doesn't' ... I am finding that I do not have to call `self dismissViewController...` just having the unwind segue completes the required move. In fact by including the `dismissViewController` method I get a warning about dismissing whilst another is animating? – StuartM Jan 15 '14 at 15:26
  • 1
    If you don't have to then you're all set. I found that when I had a modal dismiss with a custom animated transition on the dismiss I would need to manually call dismissViewController in the unwind action to start the dismiss transition. – Jesse Jan 15 '14 at 17:11
  • Thanks Jesse - I will accept the answer. I have another question open http://stackoverflow.com/questions/21142700/using-instruments-to-find-why-a-controller-is-not-calling-dealloc - which I beleive relates to the transitioning delegate not being nil and the controllers not being dealloc'd if you know about this too. Thanks – StuartM Jan 15 '14 at 17:19