I want to show 2 options like "hi" & "bye" when user completes selection on UIWebView. I have added observer to my view controller as follows. But I don't know further implementation. Please guide me.
Thanks in advance for sharing your great knowledge. Sagar | |||
Sagar, Your question is a couple of months old, but I finally figured this one out, so I figured I'd answer it in case it helps out someone else. I added the following code to the viewDidAppear: method of the view controller that contains the webview.
In my viewDidDisappear:, I go ahead and remove those items:
Then, I implemented the canPerformAction:withSender: method in the view controller. It helps to understand the concept of responders and responder chains to understand what is going on here. Basically, your uiviewcontroller is part of the responder chain, so it gets asked if it can handle any actions (like your custom actions you added above) that objects higher up the responder chain (like the UIWebView) don't know how to handle (see the UIResponder documentation and the Event Handling Guide for iOS for the gory details). Now, when canPerformAction:withSender: is called for the webview, the sender parameter is set to nil. So, I try to be a bit clever about how I write this function. Basically, I make sure that the sender is nil, I'm showing the webview to the user, and any other controls on the page aren't the first responder. If that's the case, then I check to see if this is one of the actions I defined above and retur YES if it is. In all other cases I return the default value from UIViewController by calling the same method on super.
Of course, now the next step is figuring out how to actually do something with the selection (probably by running some JavaScript in the webview). |
联系客服