I have a UIWebView inside a TableView. Essentially, the TableView is just one cell with some controllers inside. Everything works just fine, except that the webview does not receive the scroll events... is there a workaround for this?
Or should I just take the easy path and place the webview outside the tableview? (something like a footer)
Oh, you've put yourself into a world of hurt. Both of these are subclasses of UIScrollView, and UIScrollView intercepts events - it disrupts the responder chain in a way that really doesn't play nicely with others. If the event turns into a pan or zoom or another gesture the scroll view (or table view, web view, etc) responds to, then that event gets consumed and not passed onto the responder chain.
You could try creating a subclass of UITableView where you override all the event-handling methods, having them all call super and then manually pass the event on to the next responder, but I would be concerned about the law of unanticipated consequences, such as having controls unintentionally triggered when zooming or panning. Perhaps you could manually pass the even ONLY on to the web view, but that would be very kludgey and prone to breaking and would require controller code embedded in a view, which is just ugly in a .NET kind of way.
This could cause some issues in a UIScrollView, UITableView, or UIWebView subclass because of the way those classes temporarily interrupt the responder chain. If the gesture turns into a pan or zoom, you should not forward to the next responder unless you know for sure that the child UIScrollView/UITableView/UIWebView was hit, so you probably need to do a separate hit test before forwarding to the next responder. If the user touched and panned over a button, for example, you wouldn't want to forward it on because then the button would get triggered when the user meant to scroll the view.
I'd almost recommend maybe rethinking the UI. This can be done, but it's going to be a bear to handle and get all the various permutations right.
thanks!...
After reading both of your replies, I think I really should re-think my UI :-)
regards,
r./
Discussing the problem of having a UIWebView inside a UITableView, I found out that if I set my UIWebView as the cell's backgroundView :
Code:
theCell.backgroundView = myWebView;
Then, the touches events are not passed to the webview.
Instead, if I add the webview as a subview of the contentView :
Code:
[theCell.contentView addSubView:myWebView];
Then, the touches events are passed, or at least I can touch a link in the webview and load it (I did not try for scrolling my webview which was disabled).