Question

How can I place a UIWebView in a table view cell, yet maintain the UIWebView's scrollbars? My table view does have multiple cells and a header frame as well, and I do need it to be scrollable because it has many rows.

The text displays perfectly fine when I use UITextView and it shows scrollers as well, but the problem is that my content is rich text, so I don't have any other option but to show the content in UIWebView. Any ideas, hacks?

Was it helpful?

Solution

Unless Apple does something about it, this can't work. Both UITableView and UIWebView support scrollers, and they contradict with each other. UITableView scrollers take precednce so whenever a scroll operation is performed, the action is sent to UITableView instead of UIWebView.

For some reason, when using UITextView with UITableView, scrollers work for both.

OTHER TIPS

The problem with adding UIWebView into a table cell is both these objects are scrollable (tableview and webview) which will create complications if not used appropriately. Does you tableview have any cells other than uiwebview? and do you need the tableview to be scrollable? In case the tableview need not be scrollable, make scrolling enabled in the webview and disabled for the tableview. That should work.

But if you want to just display text, why not use a UITextView (though you'll face the same problem for UITextView too)?

I just found this in the UIWebView documentation:

"Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled."

The scrollbars are added automatically when you put content in your UIWebView. Be sure to uncheck "Scales Page to Fit" in Interface builder, so the page is not rescaled when displayed.

UIWebView will automatically display scrollbars when it has content that exceeds the height of the UIView.

You can put a UIWebView into a UIScrollView and have both scrollable by setting the canCancelTouchEvents property of the UISCrollView to NO. If you just flick, the UIScrollView will scroll. If you hold your finger down for a short period of time and then start to flick, the UIWebView will scroll.

Try this quick hack to see if you can force the web view to show a scroll indicator: ((UIScrollView*)[webView.subViews objectAtIndex:0]).showsVerticalScrollIndicator = YES;

The more thorough approach is to divide your cell contents into a summary and detail. Show the summary in each cell, but without details. After you select a cell, use a new screen to show the full contents of the selected cell. This completely avoids the usability issue of having a scrollable view inside of a scrollable view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top