如何找到返回YES的响应者到canPerformAction:withSender: [英] How to find the responder that is returning YES to canPerformAction:withSender:

查看:1490
本文介绍了如何找到返回YES的响应者到canPerformAction:withSender:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从UIWebView的编辑菜单中禁用定义菜单项。这应该通过实现 canPerformAction:withSender:来完成,并返回NO以禁用项目。即使这些是私人项目,似乎我应该能够返回YES的项目,我想保留和否的其他一切(如

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).

但是这不工作。 文档


如果响应者链中没有响应者返回YES,菜单命令将被禁用。注意,如果你的类返回NO为一个命令,另一个响应者进一步向上响应链可能仍然返回YES,启用命令。

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.

似乎这必须是这不工作的原因。我如何找到哪个响应者返回YES?

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

推荐答案

最后,我想出了这个函数,子视图和日志是否是第一个响应者。

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];
    }
}

我从 canPerformAction:withSender: function

Which I called from my canPerformAction:withSender: function

[self logResponderInfo:self.webView];

这写出了日志

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

它告诉我第一个响应者实际上是UIWebBrowserView。

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

这篇关于如何找到返回YES的响应者到canPerformAction:withSender:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆