Casting is not magic.
I repeat: Casting is not magic!
It does't change the run-time type of an object. If it didn't respond to a selector as a UIWebView
, it won't respond to it as a UIMenuItem
either. You have to detect the event using JavaScript and bridge your JavaScript function to Objective-C. Use the onpaste
JavaScript event handler, then do something like what is described here:
<!-- snippet from your HTML string -->
<script type="text/javascript">
function call_objc_paste(text)
{
window.location.href = "fakescheme://" + text;
}
</script>
<input type="text" onpaste="call_objc_paste(this.value);" />
// Objective-C code:
webView.delegate = self;
[webView loadHTMLString:htmlStr baseURL:nil];
- (BOOL) webView:(UIWebView *)wv
shouldStartLoadWithRequest:(NSURLRequest *)rq
navigationType:(UIWebViewNavigationType)navT
{
NSString *rqStr = rq.URL.absoluteString;
NSString *scheme = @"fakescheme://";
if ([rqStr hasPrefix:scheme]) {
NSString *pastedText = [rqStr substringFromIndex:scheme.length];
// potentially do somethin with pastedText, then
return NO;
}
// it's not our fake URL scheme, just normal navigation
return YES;
}