Html コンテンツに基づいて高さを自動変更するカスタム UIWebView 要素を作成する方法は?
カスタム TableViewCell クラスとカスタム MonoTouch Dialog Element コードを次に示します。TableViewCell クラスから高さを取得して送り返し、Element クラスの高さを設定しようとしました。しかし、私はそれを行う方法がわかりません。
public class WebContentViewCell : UITableViewCell
{
public static NSString Key = new NSString("WebContentViewCell");
public WebContentViewCell(string htmlContent, UITableView tv)
: base(UITableViewCellStyle.Default, Key)
{
View = new UIWebView();
View.LoadHtmlString(htmlContent, null);
ContentView.Add(View);
}
public void UpdateCell(string htmlContent)
{
View.LoadHtmlString(htmlContent, null);
}
public UIWebView View { get; set; }
public float Height { get; set; }
public override void LayoutSubviews()
{
base.LayoutSubviews();
var contentFrame = ContentView.Bounds;
View.Frame = contentFrame;
}
}
public class WebContentElement : Element, IElementSizing
{
private readonly string _htmlContent;
private float _height = 200;
private UIWebView _webView;
public WebContentElement(string htmlContent)
: base("")
{
_htmlContent = htmlContent;
_webView = new UIWebView();
_webView.LoadHtmlString(_htmlContent, null);
}
protected override UITableViewCell GetCellImpl(UITableView tv)
{
var cell = tv.DequeueReusableCell(WebContentViewCell.Key) ?? new WebContentViewCell(_htmlContent, tv);
return cell;
}
public float GetHeight(UITableView tableView, NSIndexPath indexPath)
{
return _height; // how to get the height based on the WebContentViewCell's content?
}
}