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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:45:26+00:00 2026-05-12T11:45:26+00:00

I am having a problem. My contextual menu is getting displayed but the menu

  • 0

I am having a problem. My contextual menu is getting displayed but the menu items are not activated.
so my new code for displaying the menu is as follows:

NSMenu *defMenu = [[[NSMenu alloc] initWithTitle:@"default Contextual Menu"] autorelease];

[defMenu insertItemWithTitle:@"Open" action:@selector(openFile) keyEquivalent:@"" atIndex:0];

[defMenu insertItemWithTitle:@"Delete" action:@selector(deleteFile) keyEquivalent:@"" atIndex:1];

return defMenu;

and function declaratons of deleteFile and openFile are as follows:

-(int)openFile;

-(int)deleteFile;

and i am calling my contextual menu as follows:

-(void)doSingleClick 
{

    if([[NSApp currentEvent] modifierFlags] & NSControlKeyMask)
    {

        NSLog(@"control clicked.......");

        [NSMenu popUpContextMenu:[self defaultMenu] withEvent:[NSApp currentEvent] forView:tableView];

        return;
    }

}

my contextual menu items are all shaded and cannot be clicked. Please can you tell where i am going wrong.

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-05-12T11:45:26+00:00Added an answer on May 12, 2026 at 11:45 am

    Your openFile: method takes an int as a parameter. Since insertItemWithTitle:action:withObject:keyEquivalent:atIndex: takes an object, the selector you give it must also take an object.

    You can use NSNumber to wrap your int as an object, and simply change your openFile: method to take an NSNumber rather than an int. Like so:

    [defMenu insertItemWithTitle:@"Open" action:@selector(openFile:) withObject:[NSNumber numberWithInt:5] keyEquivalent:@"" atIndex:0];
    
    - (void)openFile:(NSNumber *)fileNumber {
        int rowClicked = [fileNumber intValue];
        // Do whatever your old method did here
    }
    

    EDIT: To answer your updated question:

    The reason your menu items are disabled is that you’ve only told them what method name to call. You never told the items on which object instance those methods should actually be called. To fix this, you need to set the items’ target:

    NSMenuItem *openItem = [defMenu insertItemWithTitle:@"Open" action:@selector(openFile:) withObject:[NSNumber numberWithInt:5] keyEquivalent:@"" atIndex:0];
    [openItem setTarget:self];
    

    And so forth for each item you’ve got.

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

Sidebar

Related Questions

Having problem to open form in new window, script is pulled from external service.
i having problem understanding what is wrong with my inheritance. I just can not
I'm having problem on getting the file path using file upload. When I tested
I having problem figuring howto preserve the present state ...Let say I have selected
I am having problem when i save a single variable of 460 elements in
I'm having problem with dynamic_cast. i just compiled my project and tested every thing
I am having problem using variables as selectors with jquery. how do I select
Warning: This is my first IPhone Application and I'm new to Objective C, therefore
Ok, so this is really just a conceptual question I'm having a bit of
I have a data model as follows: A Customer has Products and Payment Methods.

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.