2

I need to disable the Define menu item from the edit menu on a UIWebView. This is supposed to be done by implementing canPerformAction:withSender: and returning NO for the items to disable. Even though these are private items it seems like I should be able to return YES for the items I want to keep and NO for everything else (as in this question).

However this is not working. The documentation says that

If no responder in the responder chain returns YES, the menu command is disabled. Note that if your class returns NO for a command, another responder further up the responder chain may still return YES, enabling the command.

It seems that this must be the reason this isn't working. How do I find which responder is returning YES?

Community
  • 1
  • 1
Sarah Elan
  • 2,465
  • 1
  • 23
  • 45

1 Answers1

2

In the end, I figured this out with this function which recursively goes through the subviews and logs whether they are first responder.

- (void) logResponderInfo: (UIView *)view 
{
    NSLog(@"%@ %@", NSStringFromClass(view.class), view.isFirstResponder ? @"yes" : @"no");

    for (UIView *sub in view.subviews) {
        [self logResponderInfo:sub];
    }
}

Which I called from my canPerformAction:withSender: function

[self logResponderInfo:self.webView];

This wrote out to the logs

2013-11-18 11:35:56.100 Testing[44593:a0b] CDVCordovaView no
2013-11-18 11:35:56.100 Testing[44593:a0b] _UIWebViewScrollView no
2013-11-18 11:35:56.101 Testing[44593:a0b] UIWebBrowserView yes
2013-11-18 11:35:56.101 Testing[44593:a0b] UITextSelectionView no
2013-11-18 11:35:56.102 Testing[44593:a0b] UIView no
2013-11-18 11:35:56.102 Testing[44593:a0b] UIImageView no
2013-11-18 11:35:56.103 Testing[44593:a0b] UIImageView no
2013-11-18 11:35:56.103 Testing[44593:a0b] UIActivityIndicatorView no
2013-11-18 11:35:56.104 Testing[44593:a0b] UIImageView no

which told me that the first responder was in fact UIWebBrowserView.

Sarah Elan
  • 2,465
  • 1
  • 23
  • 45
  • Awesome investigation, thanks. Note that http://stackoverflow.com/a/9048973/294884 using a non-app-store approach, you can override it, sort of. – Fattie Jun 14 '14 at 09:42
  • Also note: http://stackoverflow.com/questions/19033292/ios-7-uiwebview-keyboard-issue – Fattie Jun 14 '14 at 09:49
  • Thanks. The solution I ultimately used was based on [this answer](http://stackoverflow.com/a/14479217/1873374), using code from [here](https://gist.github.com/bjhomer/2048571). – Sarah Elan Jun 16 '14 at 13:38