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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:59:07+00:00 2026-05-16T16:59:07+00:00

I want to show 2 options like hi & bye when user completes selection

  • 0

I want to show 2 options like “hi” & “bye” when user completes selection on UIWebView.

I have added observer to my view controller as follows. But I don’t know further implementation.

[[UIMenuController sharedMenuController] addObserver:self 
                                          forKeyPath:UIMenuControllerWillShowMenuNotification
                                             options:nil
                                             context: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-05-16T16:59:08+00:00Added an answer on May 16, 2026 at 4:59 pm

    Sagar,

    Your question is a couple of months old, but I finally figured this one out, so I figured I’d answer it in case it helps out someone else.

    I added the following code to the viewDidAppear: method of the view controller that contains the webview.

    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
    
        UIMenuItem *customMenuItem1 = [[[UIMenuItem alloc] initWithTitle:@"Custom 1" action:@selector(customAction1:)] autorelease];
        UIMenuItem *customMenuItem2 = [[[UIMenuItem alloc] initWithTitle:@"Custom 2" action:@selector(customAction2:)] autorelease];
        [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:customMenuItem1, customMenuItem2, nil]];
    }
    

    In my viewDidDisappear:, I go ahead and remove those items:

    - (void)viewDidDisappear:(BOOL)animated {
        [super viewDidDisappear:animated];
    
        [[UIMenuController sharedMenuController] setMenuItems:nil];
    }
    

    Then, I implemented the canPerformAction:withSender: method in the view controller. It helps to understand the concept of responders and responder chains to understand what is going on here. Basically, your uiviewcontroller is part of the responder chain, so it gets asked if it can handle any actions (like your custom actions you added above) that objects higher up the responder chain (like the UIWebView) don’t know how to handle (see the UIResponder documentation and the Event Handling Guide for iOS for the gory details).

    Now, when canPerformAction:withSender: is called for the webview, the sender parameter is set to nil. So, I try to be a bit clever about how I write this function. Basically, I make sure that the sender is nil, I’m showing the webview to the user, and any other controls on the page aren’t the first responder. If that’s the case, then I check to see if this is one of the actions I defined above and retur YES if it is. In all other cases I return the default value from UIViewController by calling the same method on super.

    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
        if (webView.superview != nil && ![urlTextField isFirstResponder]) {
            if (action == @selector(customAction1:) || action == @selector(customAction2:)) {
                return YES;
            }
        }
    
        return [super canPerformAction:action withSender:sender];
    }
    

    Of course, now the next step is figuring out how to actually do something with the selection (probably by running some JavaScript in the webview).

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

Sidebar

Related Questions

...I want to Show the 'delete' button when user is an admin, and show
We want to show a hint for a JList that the user can select
I want to show HTML content inside Flash. Is there some way to do
I want to show a chromeless modal window with a close button in the
I want to show the publish date in the About dialog.
I want to show a table of fixed width at the center of browser
I want to show first element that is hidden by jquery. my html code
I want to show a label rotated 90 degrees (so I can put a
I want to show a message box when users trying to do any major
I want to show an image from an URL with a certain width and

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.