2

Does any know how to get around viewDidAppear not being hit when exiting from a UIModalTransitionStylePartialCurl segue?

- (IBAction)buttonSelector:(id)sender
{

    // creating object for title screen
    UIStoryboard *storySelection =[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    // creating object for profile view
    selectorViewController = [storySelection instantiateViewControllerWithIdentifier:@"Verse Selector"];

    // setting the transition style
    selectorViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;

    // performing the segue
    [self presentViewController:selectorViewController animated:YES completion:nil];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // testing for a return from segue
    if (selectorViewController != nil)
    {
        // getting the chosen values from the instance
        chosenBook = selectorViewController.chosenBook;

        // setting instance to nil for garbage collection
        selectorViewController = nil;
    }
}
lnafziger
  • 25,760
  • 8
  • 60
  • 101
Grymjack
  • 529
  • 1
  • 10
  • 21

2 Answers2

1

EDIT

It looks like the best route is to implement a custom delegate protocol which notifies the presenting view controller that the presented view controller is being dismissed.

lnafziger
  • 25,760
  • 8
  • 60
  • 101
  • I placed the function in the controller that started the curl transition and that function was not triggered upon return to that controller. – Grymjack Feb 25 '13 at 00:25
  • It really should be.... Did you try putting a breakpoint at the beginning of the function to see if it is ever called? – lnafziger Feb 25 '13 at 02:19
  • yup, breakpoint confirms that upon exit from the 'curl' transition `- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion` is not fired. It's quite possible that I'm doing something stupid. Do I call the dismissal the same way in the view being dismissed? `[self dismissViewControllerAnimated:YES completion:nil];` – Grymjack Feb 25 '13 at 06:33
  • right now I'm cheating by passing the data back through a singleton – Grymjack Feb 25 '13 at 06:36
  • You should just call `[self dismissViewControllerAnimated:YES completion:NULL];`... – lnafziger Feb 25 '13 at 06:46
  • that's what I'm doing. `viewDidAppear` is called when I use any other transition than curl, but no matter what transition I use it never calls the `-(void)dismissViewControllerAnimated` override. I copied the code you posted right into the view controller that is performing the segue. – Grymjack Feb 25 '13 at 06:57
  • Yeah, `viewDidAppear` isn't called with this transition, but I'm not sure why the other one isn't working for your... Sorry! – lnafziger Feb 25 '13 at 07:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25063/discussion-between-grymjack-and-lnafziger) – Grymjack Feb 25 '13 at 07:10
  • thanks to lnafziger in helping to implement a custom dismissal protocol. We were not able to figure out why `(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion` wouldn't fire. If anyone has any further thoughts on that, it would be appreciated. – Grymjack Feb 25 '13 at 08:40
0

One way to do this would to be to set your initial view controller as a delegate to your modally presented view controller. Before presenting the view controller:

selectedViewController.delegate = self;
[self presentViewController:selectorViewController animated:YES completion:nil];

Then, in the modal view controller, in whichever method dismisses the modal presentation, directly call viewDidAppear: on the original view controller.

- (void)doneButtonPressed:(id)sender
{
    [self.delegate viewDidAppear:NO];
    [self.delegate dismissModalViewControllerAnimated:YES];
}
Patrick Goley
  • 5,397
  • 22
  • 42