Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Dude, I ran into the same problem.. and here is what I found about using parentViewController:</p> <blockquote> <p>Note that as of 5.0 this no longer will return the presenting view controller.</p> </blockquote> <p>This was written in the header file of UIViewController...</p> <p>I am using ShareKit, and the modalViewController was working perfectly in iOS4, but in iOS5, it just won't dismiss itself! This is because in their code, they are using:</p> <pre><code> [[currentView parentViewController] dismissModalViewControllerAnimated:animated]; </code></pre> <p>and parentViewController will return nil, since this is a modal presented view controller...</p> <p>By searching for a solution, I found your question.. So, I decided to fix it myself :P</p> <p>I changed the previous line to this:</p> <pre><code> [currentView dismissModalViewControllerAnimated:YES]; </code></pre> <p>Works like a charm.</p> <hr> <p><strong>EDIT:</strong> Depending on how you interpret the original question, there are two answers. Here's the second:</p> <p>In iOS5 it seems that the modal controller only dismisses itself when you click the curl, but not above the curl or the backgound. In iOS5, in order to actually get the modal view to dismiss itself when tapping the background or above the curl I added the following code to the controller, to listen to taps on the modal view, but ignore taps to buttons. This should mimic the behavior in previous version of iOS when working with a modal controller with page curl. </p> <pre><code>- (void)viewDidLoad { UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; tap.numberOfTapsRequired = 1; tap.numberOfTouchesRequired = 1; tap.delegate = self; [backgroundView addGestureRecognizer:tap]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ //change it to your condition if ([touch.view isKindOfClass:[UIButton class]]) { return NO; } return YES; } - (void)handleTap:(UITapGestureRecognizer *)sender { [self dismissModalViewControllerAnimated:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload