Resizing a UIWebview inside UITableView

PreranaPPreranaP USUniversity

Hello All,
I am trying to implement UITableView with each row containing uiwebview each rendering an html content of variable length. Issue is I am unable to get it resized as per the content size, there is white space after the last web view in the row, is it looking something like the following screenshot :


Has anyone implemented something like this(UITableView with UIWebView with variable heights) successfully? I have already spent 3 days trying to get it working correctly, tried working around loads of links on StackOverflow but it does not seems to work :(

Currently I am doing the following :

Calculating the height of the UIWebview once its loaded in LoadFinishMethod and setting it to a public static property rowHeight:

          void HtmlView_LoadFinished (object sender, EventArgs e)
        var webview = (UIWebView)sender;
        Console.WriteLine("Webview load finished");
        string result = htmlView.EvaluateJavascript(@"document.body.offsetHeight;");
        Console.WriteLine("Height inside LoadFinished"+result);
        int height = Int32.Parse(result);
        htmlView.Frame= new CGRect (ContentLeftMargin, 18, ContentView.Bounds.Width- ContentLeftMargin, height);
        htmlView.ScrollView.Bounces = false;


then accessing this property inside GetHeightForRow of UITableViewSource :

    public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
                Console.WriteLine ("HTML: content found-->Height"+ActivityView.rowHeight);
                return ActivityView.rowHeight;  


the web views are getting loaded but leaving huge blank space at the bottom :


Is it not setting the height of various web views correctly at correct index, is it something I am missing here ? Do I need to maintain different heights in some array and then set it accordingly, I am assuming GetHeightForRow method handles this correctly , am I wrong ?

I am literary at my wits end! Any help or guidance will be really appreciated!! Thanks a ton in advance!



  • PreranaPPreranaP USUniversity

    Resolved it by using UILabel instead of UIWebivew to display the html content :) Happy coding!

Sign In or Register to comment.