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 6058251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:34:44+00:00 2026-05-23T08:34:44+00:00

I am currently trying to nest a UIWebView (among other elements) into a custom

  • 0

I am currently trying to nest a UIWebView (among other elements) into a custom UITableViewCell subclass.

I need to dynamically determine the size of the cell (using heightForRowAtIndexPath) but for some reason when I do it like so, the height always gets printed as 0:

UIWebView* wv = [[[UIWebView alloc] init] autorelease];
[wv loadHTMLString:body baseURL:nil];
[wv setNeedsLayout]; //I don't think these are necessary but I tried anyway.
[wv setNeedsDisplay];
CGSize wvSize = [wv sizeThatFits:webViewBounds]; 
NSLog(@"WVHEIGHT %f", wvSize.height); //THIS IS WHERE IT PRINTS.
CGFloat retVal = 10.0f;
retVal += 50 > wvSize.height ? 50 : wvSize.height;
retVal += 2 + 15 + 10;

return retVal;

Now, if I do that exact same calculation using the cell.webView that I have access to in cellForRowAtIndexPath, it returns a non-zero value. However, I’d really like to avoid loading an entire cell just to figure out how tall it should be…

Additionally, UIWebView is very slow at rendering text (and it is unfortunately not negotiable that I use UIWebView), so I was wondering if there’s a way to tell it to display the typical Apple “rotating gear” activity icon until it has its text fully loaded and ready to render.

  • 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-05-23T08:34:45+00:00Added an answer on May 23, 2026 at 8:34 am

    I would recommend hiding each UIWebView until it is done loading, and showing a loading indicator instead. I would then make a dictionary with keys that match the tags, and for each entry in the dictionary, I would store the size of the UIWebView.

    Make your controller conform to the UIWebViewDelegate protocol, and use the following code:

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
    
        NSString *output = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('this').offsetHeight;"];
    
        [self.webViewHeights setValue:[output floatValue] forKey:[NSString stringWithFormat:@"%f", webView.tag]];
    
    }
    

    After that, add code to hide your loading view and display your UIWebView, then call a table reload. In your cell height method, just check the correct array element for your UIWebView height.

    Edit:

    It seems I left out the important part!

    OK, so, to create non-visible UIWebViews, you just need to create them, but not actually add them to a view. For example, you could do something like this in your viewDidLoad method:

    UIWebView *newWebView = [[UIWebView alloc] initWithFrame:newFrame];
    [newWebView loadHTMLString:body baseURL:nil];
    newWebView.tag = 1;
    
    [self.webViewDictionary setObject:newWebView forKey:@"1"];
    

    Then in your table code, say something like

    NSString *tagString = [NSString stringWithFormat:@"%d", indexPath.row];
    UIWebView *curWebView = [self.webViewDictionary objectForKey:tagString];
    
    if (curWebView.loading == NO) {
    
        CGRect newFrame = curWebView.frame;
        newFrame.size.height = [self.webViewHeights objectForKey:tagString];
        curWebView.frame = newFrame;
    
        [cell addSubview:curWebView];
    
    } else {
    
        UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorStyleGray];
    
        [cell addSubview:activityIndicator];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get into the Java EE development with the Spring framework.
Im currently trying to bind the DataGrid.ItemsSource to a custom RowCollection, which implements IList
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to read in an XML file, make some minor changes (alter
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to build a personal website to create a presence on the
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console
My team is currently trying to automate the deployment of our .Net and PHP
I'm currently trying to debug a customer's issue with an FTP upload feature in
I'm currently trying ElementTree and it looks fine, it escapes HTML entities and so

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.