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

  • SEARCH
  • Home
  • 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 9038693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:32:57+00:00 2026-06-16T09:32:57+00:00

I have a UIViewController then when I longpress to self.view it will push a

  • 0

I have a UIViewController then when I longpress to self.view it will push a popup (MenuViewController). But when I try to remove popup by removeFromSuperview it still appears

You can see more detail of my problem with this http://www.youtube.com/watch?v=nVVgmeJEnnY

ViewController.m

#import "MenuViewController.h"
@interface ViewController () {
    MenuViewController *menu;
}
....
- (void)viewDidLoad
{
    ....
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(albumButtonPressed : ) name:@"albumButtonPressed" object:nil];
    ....
}

....

-(void)albumButtonPressed : (NSNotification*) notification {
    UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init];
    photoPicker.delegate = self;
    photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:photoPicker animated:YES];
}

...

-(void)handleLongPress:(UILongPressGestureRecognizer*)recognizer {
    menu = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
    if (self.imageView.image != nil) {
        menu.imageAdded = YES;
    }
    [self.view addSubview:menu.view];
}

MenuViewController.m

-(IBAction)albumButtonPressed:(id)sender {
    [self.view removeFromSuperview];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"albumButtonPressed" object:nil];
}
  • 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-16T09:32:59+00:00Added an answer on June 16, 2026 at 9:32 am

    Setting aside my reservations about not applying proper view controller containment, the problem is that your handleLongPress will be called multiple times with different recognizer.state values, once as UIGestureRecognizerStateBegan and again as UIGestureRecognizerStateEnded. You should be checking the state of the gesture, e.g.:

    -(void)handleLongPress:(UILongPressGestureRecognizer*)recognizer {
        if (recognizer.state == UIGestureRecognizerStateEnded) {
            menu = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
            if (self.imageView.image != nil) {
                menu.imageAdded = YES;
            }
            [self.view addSubview:menu.view];
        }
    }
    

    Original Answer:

    I’d suggest putting a NSLog or breakpoint at your code with the removeFromSuperview and see if you’re even getting to that piece of code.

    There are some clear problems here. Specifically, you’re not adding added the view associated MenuViewController in handleLongPress properly. If you want a subview with it’s own controller, you have to use containment (and that only works with iOS 5 and later). And in containment, you have critical methods like addChildViewController, etc. See Creating Custom Container View Controllers in the View Controller Programming Guide or see WWDC 2011 – Implementing UIViewController Containment. And, as an aside, you’re also maintaining a strong reference to MenuViewController, so even if you succeeded in removing it’s view, you’d leak the controller.

    Spend a little time going through the containment documentation/video, and I think you’ll want to revisit how you’re presenting your menu. This is dense reading, but worth really understanding. Containment is powerful, but has to be done right.

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

Sidebar

Related Questions

I have UINavigationController and UIViewController, then I push another viewcontroller, but I don't need
I have a UIViewController that should lazily load a view and then keep it
I have a UIViewController view as a subview/modal on top of another UIViewController view,
I have a UIViewController that has an UIPopoverController that has an UINavigationController then a
I have a UIViewController as root vc, attached to the window. Then I simply
I have a UIViewController, on top I put an UIImageView, then a UIScrollView. I
I have a UIViewController whose view has a custom subview. This custom subview needs
I have a UIViewController inside of which I put a UIWebView Then I added
I have a UIViewController based app and I want to changes data on view
I have a UIViewController which adds a UITableView and a UIToolbar to its view.

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.