Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:11:48+00:00 2026-06-08T14:11:48+00:00

This seems like a common problem, but I’m unable find an adequate solution. I’m

  • 0

This seems like a common problem, but I’m unable find an adequate solution. I’m trying to re-size a bunch of UIWebViews to fit their content, but it doesn’t seem to work properly. The best solution I’ve found so far is this answer, but it only appears to work occasionally in my solution. The idea is to re-size the UIWebView in the webViewDidFinishLoad: delegate method. However, this still doesn’t get the right size. If I trigger the update at some undefined time after webViewDidFinishLoad:, the content does get sized correctly.

I will describe my situation below, and I’ll paste relevant source on Gist.

Problem Description

I have a situation where I’m getting data from a JSON API and displaying the data in webviews. The API returns an array of objects, and each object has a “content” field with HTML-formatted text. The designers have given a structure which involved a (mostly) hidden view that you swipe up to reveal, which contains a scroll view of all the content, formatted in a very particular way.

To implement this, I have three view controllers: The main view controller, the secondary view controller which you swipe up on the main view controller to reveal, and a tertiary view controller that displays one item of html-formatted content from the JSON API results.
The secondary view controller contains a UIScrollView and an array of tertiary view controllers. Each tertiary view controller contains a UIWebView to display the HTML-formatted content, and labels for displaying other attributes of the JSON object. Because the tertiary views will be displayed inside a UIScrollView in the secondary view, the tertiary views’ UIWebView needs to be re-sized to fit its content and have user interaction disabled in order to prevent a confusing scroll-view-in-scroll-view scenario.

The process to get all this to work is as follows:

  1. First, on the Primary controllers ViewDidLoad, load up and display the secondary view
    and an activity indicator so the UI does not appear to freeze
  2. Next, load the data from the JSON API
  3. When the data from the API has loaded (notified via a delegate), construct tertiary
    view controllers, set their attributes from the loaded data and add them to the secondary
    controller’s list.
  4. Once that is finished, call the Secondary controller’s setup method. This method loops
    through the list of tertiary controllers and calls their setup methods in turn
  5. Each tertiary controller’s setup method sets the text for the labels and sets the
    content for the UIWebView using loadHTMLString: with a pre-defined html file’s content,
    with the content of the JSON object substituted in.
  6. On the tertiary controller’s webViewDidFinishLoad: delegate method, using the
    method at this answer, re-size the web view based on the content size.
  7. Re-size the tertiary controller’s view to fit the web view and position any labels that
    go underneath the web view
  8. The tertiary controller then calls a delegate method to notify the secondary controller
    that it has finished loading. The secondary controller keeps tabs on which of its
    tertiary controllers have finished loading.
  9. When all tertiary controllers are finished loading, the secondary controller loops
    through its list and adds the tertiary views to it’s UIScrollView’s content, adjusting
    frames and the content height as it goes.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:11:49+00:00Added an answer on June 8, 2026 at 2:11 pm

    If you are using iOS 5.0, you could probably use webview.scrollView.contentsize, otherwise you can also get the content size through javascript.

    CGFloat newHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
    

    or alternatively

    CGFloat newHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight;"] floatValue];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems like this is a common problem, but I can't seem to find
This seems like such a simple issue but I cannot find an elegant solution.
This seems like a pretty common problem, but I haven't found any sort of
This seems like it should be a common problem but I'm having trouble finding
This seems like it would be a common issue to be but I don't
This seems like the simplest Git question, but I can't find ANYTHING on it.
This seems like it should be easy, but I can't quite find an explanation
This seems to be a fairly common problem, but the solutions that I have
This seems to be a more common problem, but when I try to use
This seems like a common question but search is not returning anything. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.