私がやっていることは、いくつかのHTMLリソースファイルをUITableViewセルに読み込むことです。私はセルの高さをUIWebViewのコンテンツサイズに応じて調整したいと思っていました。以下は私のテストコードの一部です。Dynamic UITableViewCell iOSでUIWebViewを含むセルの高さ
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"TableCellID";
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil];
cell = [nibArray objectAtIndex:0];
}
NSString *htmlFileName = [NSString stringWithFormat:@"page%ld", (long)indexPath.row];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:htmlFileName ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[cell.webView loadHTMLString:htmlString baseURL: [[NSBundle mainBundle] bundleURL]];
return cell;
}
私は私のCustomTableViewCell.xibを記述した場合、それはコンテンツビュー内部のUIWebViewを持っているとのUIWebViewは、与えられた制約を以下ました。
ContentView.Bottom = WebView.Bottom + 8
ContentView.Top = WebView.Top +8
ContentView.Leading = WebView.Leading + 8
ContentView.Trailing = WebView.Trailing + 8
HTMLファイルにはJavaScriptまたはCSSコンテンツはありません。以下のようにシンプル。
<html>
<header>
</header>
<body>
<p>eeeee eeeee eeeee eeeee eeeee eeeee eeeee eeeee eeeee eeeee</p>
</body>
</html>
私の出力は以下のようなイメージです。
私が一番上に説明したように、私のWebページには、任意のJavaScriptを含んでいません。だから私はstringByEvaluatingJavaScriptFromString
メソッドを使用してテキストを返すことができないかもしれません。
[既に読み込まれている表のセルの高さを変更するにはどうすればよいですか?](http://stackoverflow.com/questions/20666405/how-do-i-change-the-height-of-すでにロードされているテーブルセル) –
ロード後のWebviewの高さの計算が簡単になり、webViewの高さに基づいてセルを調整させることができると思います。 – Joshua