How to find the responder that is returning YES to canPerformAction:withSender:

蹲街弑〆低调 提交于 2019-12-06 07:23:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!