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 8943343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:44:56+00:00 2026-06-15T11:44:56+00:00

I have an application with a UITabBar . Every tab is a UINavigationController with

  • 0

I have an application with a UITabBar. Every tab is a UINavigationController with several UIViewControllers inside. One of those View Controllers contains a UITableView, and I want to display a floating menu for deleting the long pressed UITableViewCell.

I am using UIMenuController but it’s not displayed because the cell refuses to become first responder.

Here’s my code:

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
        lpgr.minimumPressDuration = 1.0; //second
        [table addGestureRecognizer:lpgr];

        [lpgr release];
    }

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        CGPoint p = [gestureRecognizer locationInView: table];

        NSIndexPath *indexPath = [table indexPathForRowAtPoint:p];
        if (indexPath != nil) {
            UITableViewCell* cell = [self tableView:table cellForRowAtIndexPath: indexPath];

            [cell becomeFirstResponder];
            UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"Delete" action:@selector(delete:)];

            UIMenuController *menu = [UIMenuController sharedMenuController];
            [menu setMenuItems:[NSArray arrayWithObjects:delete, nil]];
            [menu setTargetRect:cell.frame inView:cell.superview];
            [menu setMenuVisible:YES animated:YES];
        }
    }
}

On the UITableViewCell I have overriden the method:

-(BOOL) canBecomeFirstResponder {
    return YES;
}

Any ideas on why the cell is not becoming the first responder?

Thanks!

  • 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-15T11:44:57+00:00Added an answer on June 15, 2026 at 11:44 am

    I think I fixed your code 🙂

    -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
        if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
            CGPoint p = [gestureRecognizer locationInView: self.tableView];
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
            if (indexPath != nil) {
    
                [self becomeFirstResponder];
                UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"Delete" action:@selector(customDelete:)];
    
                UIMenuController *menu = [UIMenuController sharedMenuController];
                [menu setMenuItems:[NSArray arrayWithObjects:delete, nil]];
                [menu setTargetRect:[self.tableView rectForRowAtIndexPath:indexPath] inView:self.tableView];
                [menu setMenuVisible:YES animated:YES];
            }
        }
    }
    
    - (void)customDelete:(id)sender {
    //
    }
    
    - (BOOL)canBecomeFirstResponder {
        return YES;
    }
    
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
        if (action == @selector(customDelete:) ){
            return YES;
        }
        return NO;
    }
    

    I did the following..

    1. [self becomeFirstResponder];
    2. [menu setTargetRect:[self.tableView rectForRowAtIndexPath:indexPath] inView:self.tableView];
    3. Added true for canPerformAction Not mostly needed if you have implemented the function

    Please change the tableview and other things to your local reference variables 🙂

    Good read – http://www.intridea.com/blog/2010/12/22/developers-notes-for-uimenucontroller

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

Sidebar

Related Questions

In my application I have UINavigationController inside UITabBar When I display my HUD the
In my application I have a uitabbar contoller for managing the three view controllers.
I have a UITabBar + UINavigationController application which often needs data from the internet.
I have a UITabBar in my application with three tab bar items. At certain
I have a UITabBar in the detail view of my navigation based application. I
I have application where i have two view controllers my first view and second
I have uitabbar application and I Want to rotate just one ViewController with chart
I have a UITabBar application, which has three tabs. The first tab has a
I have an application made by a UITabBar with three tabs. One of these
My application is a Tabbed Application, and it have several controllers under the tabBarController.

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.