views:

386

answers:

1

I want to be able to embed a UIWebView into a tableview's cell (grouped style).

The web view is long (longer than the screen), and I want it to display it's full length. So there is no scrolling within the web view itself, just on the table.

------------------------
| a normal table cell  |
------------------------
| a normal table cell 2|
------------------------
|   a long webview     |
|  which doesn't scroll|
|  within itself       |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
------------------------

The web view will have various heights so how can I discover the the height of the webview in order to adjust the height in heightForRowAtIndexPath?

A: 

Here's how you could do it, but see my caution below:

You could load the web view, then use a javascript function to determine the height of the content. You could then use [myWebView stringByEvaluatingJavaScriptFromString: ..] to get the height.

Here's the problem. UIWebViews are fairly slow. The table can't present itself until it knows the heights of the rows, because that's how it determines which table cells to fetch. So scrolling your table view will be jerky, because every time you scroll down to a new cell, the height will need to be computed.

There are two approaches you can take:

1) Don't use a UIWebView embedded in a UITableCell. Instead use a UILabel and determine its height using some of the NSString convenience methods for doing this.

2) Use a UIWebView for the entire table. You can very closely simulate a tableview by doing this, and you will get the UI you need. To handle things like clicks, use the URL loading hooks provided by UIWebViewDelegate.

Chris Garrett