Note that there are some explanatory texts on larger screens.

plurals
  1. POUIWebView document stays height of tallest content
    primarykey
    data
    text
    <p>I'm loading content into a UIWebView with the following call:</p> <pre><code>NSString *detailHtmlString = [NSString stringWithFormat:@"&lt;html&gt;&lt;head&gt;&lt;style&gt;body {background: black;color: white;line-height: 1.4em; font-family: sans-serif; margin: 0; padding: 0 0 30px 0;width: 280px;} p {margin-top: 10px;}&lt;/style&gt;&lt;/head&gt;&lt;body id=\"content\"&gt;%@&lt;/body&gt;&lt;/html&gt;",[currentWeek objectForKey:@"post_content"]]; [weekDetailController.movie_detail loadHTMLString:detailHtmlString baseURL:nil]; </code></pre> <p>Then, after it it finishes loading:</p> <pre><code>- (void) webViewDidFinishLoad:(UIWebView *)sender { [self performSelector:@selector(calculateWebViewSize) withObject:nil afterDelay:0.1]; } - (void) calculateWebViewSize { [weekDetailController.movie_detail sizeToFit]; float newHeight = [[weekDetailController.movie_detail stringByEvaluatingJavaScriptFromString :@"document.getElementById(\"content\").offsetHeight"] floatValue]; newHeight += 300; //height of the other elements NSLog(@"Height: %f",newHeight); CGRect frame = weekDetailController.movie_detail.frame; NSLog(@"Height was: %f",frame.size.height); frame.size.height = newHeight; weekDetailController.movie_detail.frame = frame; [scrollView.scrollView setContentOffset:CGPointZero]; [scrollView.scrollView setContentSize:CGSizeMake(frame.size.width, frame.size.height)]; } </code></pre> <p>This works great the first time the view is loaded, but on subsequent views, when different content has been loaded into the UIWebView (using the same call as above), the JavaScript call to get the height returns larger and larger values -- even if the content is smaller, it still returns the height of the largest amount of content that had been in the view at some point. I've tried loading a blank HTML string into the view to "clear" it, but that doesn't seem to help either.</p> <p>Any hints would be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload