I have created a subclass of UIWebView and have added a UIView on top of it in order to catch the touch events and use them.
Now, due to the extra view added on top of the UIWebView the text selection is not working at all. When I remove the extra UIView the text gets selected but then I cannot identify the events.
Is there a way by which both the functionalities can co-exist?
[EDIT]
May be my post was not clear enough. When I subclass UIWebView to handle events, selection stops working. I cannot select text for copy anymore. Any ideas why?
"The UIWebView class should not be subclassed." - from Apple's
UIWebView
docs.It sounds like you're trying to mess with how a person interacts with a web page, which is likely to get you rejected from the app store. (For a lot of possible rejection reasons, check out app rejected.)
If you're not worried about that, here is some advice that might help you achieve your goals:
webView:shouldStartLoadWithRequest:navigationType:
method of theUIWebViewDelegate
protocol. Very handy.stringByEvaluatingJavaScriptFromString:
, a method ofUIWebView
itself. Just pass in your javascript as a string.And, in case that doesn't give you want you want (in which case you're really going to tick off them app store review guys), then you can probably do what you're already doing, and just propagate all those
UITouch
s right on through to theUIWebView
itself. Something like this, as an example (in the overlappingUIView
):That way you can have your cake (get the user touch info) and eat it too (have the web page act as it normally does).
Not what you want to hear, but you definitely need to rethink your strategy to get the functionality you want.
UIWebview has a lot of complex behavior, it encapsulates an entire web rendering engine.
You can probably achieve your goals a different way (perhaps a toolbar item) or the functionality you desire may be hidden in a delegate method.