Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:42:55+00:00 2026-06-07T14:42:55+00:00

I set up a mechanism where a modal view controller can be dismissed by

  • 0

I set up a mechanism where a modal view controller can be dismissed by tapping the outside of the view. The set up is as follows:

- (void)viewDidAppear:(BOOL)animated
{
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
    [recognizer setNumberOfTapsRequired:1];
    recognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
    [self.view.window addGestureRecognizer:recognizer];

}

- (void)handleTapBehind:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded)
    {
        CGPoint location = [sender locationInView:nil]; //Passing nil gives us coordinates in the window

        //Then we convert the tap's location into the local view's coordinate system, and test to see if it's in or outside. If outside, dismiss the view.

        if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]) 
        {
            [self dismissModalViewControllerAnimated:YES];
            NSLog(@"There are %d Gesture Recognizers",[self.view.window gestureRecognizers].count);
            [self.view.window removeGestureRecognizer:sender];
        }
    }
}

This works amazing for dismissing a single modal view. Now suppose I have two modal views, one called from within the root view controller (View A) and then another modal called from within the first modal (View B)

Kind of like this:

Root View -> View A -> View B

When I tap to dismiss View B, all is well. However I get an EXC_BAD_ACCESS error when I try to dismiss View A. After turning on zombies, it seems that View B is still getting the message handleTapBehind: sent to it, even though it’s been dismissed and out of memory after View B was closed.

My question is why is View B still being messaged? (handleTapBehind: make sure that gesture recognizer should have been removed from the associated window.) And how can I get it to be sent to View A after View B is already dismissed.

PS. The code above appears both inside the controller for View A and for View B, and it is identical.

EDIT

Here’s how I am calling the modal view controller, this code is inside a view controller that is within the standard view hierarchy.

LBModalViewController *vc = [[LBModalViewController alloc] initWithNibName:@"LBModalViewController" bundle:nil];
[vc.myTableView setDataSource:vc];
[vc setDataArray:self.object.membersArray];

[vc setModalPresentationStyle:UIModalPresentationFormSheet];
[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

[vc.view setClipsToBounds:NO];

[self presentViewController:vc animated:YES completion:nil];

// This is a hack to modify the size of the presented view controller
CGPoint modalOrigin = vc.view.superview.bounds.origin;
[[vc.view superview] setBounds:CGRectMake(modalOrigin.x, modalOrigin.y, 425, 351)];
[vc.view setBounds:CGRectMake(modalOrigin.x, modalOrigin.y, 425, 351)];

That’s pretty much it, everything else is pretty standard.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:42:56+00:00Added an answer on June 7, 2026 at 2:42 pm
    [self dismissModalViewControllerAnimated:YES];
    
    [self.view.window removeGestureRecognizer:sender];
    

    Should be:

    [self.view.window removeGestureRecognizer:sender];
    
    [self dismissModalViewControllerAnimated:YES];
    

    else you will get undefined results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I set some group policy rule or mechanism to make sure that
I set up a project according to the recommendation here: http://www.haskell.org/haskellwiki/Structure_of_a_Haskell_project How can I
My boss wants me to set up an archiving mechanism such that a table
Can I set Tomcat (or my webapp if it's done that way) to require
I have a set of the virtual devices (D). Devices can be cross-connected (assume,
I have Basic Authorization mechanism on the server for WSDL/SOAP. How I can send
I have a layer-hosting view set up like this in a custom NSView subclass:
Is there a similar mechanism in Python, to the effect set -x has on
set(TestProject_additional_libs optimized foobar.lib debug foobard.lib } especially what is optimized/debug mean here? Is this
set Unified=C:\Workspaces\Main\Unified\UnifiedFX.sln set Fullserver=C:\Workspaces\Main\Unified\FullServer\Tests\FullServer.Automation\FullServer.Automation.csproj set Management=C:\Workspaces\Main\Unified\Management\Tests\Management.Automation\Management.Automation.csproj set Move=C:\Workspaces\Main\Unified\Move\Tests\Move.Automation\Move.Automation.csproj set d64=Debug|x64 set d86=Debug|x86 for %%a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.