SetFrame of the UIWebView
I'm loading an HTML string into a UIWebView. When the UIWebView finishes loading, I resize its height like this:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
float newSize = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] floatValue];
[self.webV开发者_Python百科iewContent setFrame:CGRectMake(self.webViewContent.bounds.origin.x,
self.webViewContent.bounds.origin.y,
self.webViewContent.frame.size.width,
newSize)];
Everything works fine until a certain height. When the HTML string gets really long - 60 000px, for example - then I get a crash. Any ideas, how could I avoid the crash? I tried to find examples where a UIWebView is being tiled, but I couldn't find anything useful.
You're almost certainly running out of memory. I've determined through experimentation that UIWebView allocates memory based on the frame size. You can have a seemingly infinite contentSize and iOS will handle the memory for you as content scrolls in and out of the visible frame.
I had to give up on a design that tiled UIWebViews inside of a UIScrollView. BTW, this behavior changed somewhere around iOS 4.2. It used to be possible to tile UIWebViews with very large frame sizes and the memory was constrained by the frame size of the containing UIScrollView.
精彩评论