Luuk D. Jansen
Luuk D. Jansen

Reputation: 4508

Estimating the height of a UIWebView

I like to estimate the size an UIWebView is going to take, as I use the webview in a table and if I know the estimated height I can resize the tablecell to the correct height straight away.

So when I get the HTML, I planned to fire a low priority background threat to create the WebViews, calculate the size, and store this in the database with the HTML. Then when the user opens the article the height is available.

But when I do it this way I get the following error:

bool _WebTryThreadLock(bool), 0xb59b610: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

Is there a way to determine the height of the HTML without causing this problem?

Upvotes: 2

Views: 175

Answers (1)

tillerstarr
tillerstarr

Reputation: 2646

You can make the UIWebView not visible, but it has to be on the main thread.

Try:

webView.layer.zPosition = -1.0;
webView.userInteractionEnabled = NO;

Upvotes: 1

Related Questions