Search code examples
iosuiwebviewuiwebviewdelegatesizetofit

UIWebView's sizeToFit works only once


In my custom UIViewController I have two distinct UIWebViews for which my custom UIViewController is the delegate. In webViewDidFinishLoad:webView I call [webView sizeToFit] and I can confirm it gets called twice, one for each UIWebView. However, to my great dismay, it only seems to affect the first one that gets called, while the other one remains unchanged. Obviously both their contents exceed the bounds, so I expect them to be resized accordingly.

Now, after lots of hours spent on this issue, how am I even supposed to proceed to understand what's wrong?

EDIT: Alright, apparently the problem is that the view in which I put the second UIWebView is not visible on the screen when I call sizeToFit. Calling it with a delay after the view is shown results in the expected behaviour. Now I have to find a way to do this without showing it, because I need to to be visible at a later time. Ideas?


Solution

  • It seems that doing that on viewDidAppear works like a charm.