webview の高さに応じて、セルにカスタムの高さを持たせようとしています。
現在、webview の frame.size.height を NSMutableArray に追加しようとしていますが、これはもちろん insertObject でクラッシュします (ここで試した解決策はかなりずさんです)。
どうすればこれを達成できますか?
int indexPathIntValue;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifer = @"PictureCell";
InspirationFeedCell *cell;
cell = (InspirationFeedCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifer];
NSBundle *mainBundle = [NSBundle mainBundle];
if (cell == nil) {
[mainBundle loadNibNamed:@"PictureCell" owner:self options:nil];
cell = self.feedCell;
self.feedCell = nil;
}
indexPathIntValue = indexPath.row;
//Here I deleted some code that fetches descriptionWebString
[cell.feedWebView setDelegate:self];
[cell.feedWebView loadHTMLString:descriptionWebString baseURL:nil];
return cell;
}
-(void) webViewDidFinishLoad:(UIWebView *)webView {
CGRect frame = webView.frame;
frame.size.height = 1;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
webView.frame = frame;
int heightOfWebViewInt = frame.size.height;
[sizeOfWebViewCell insertObject:[NSNumber numberWithInt:heightOfWebViewInt] atIndex:indexPathIntTest];
DLog(@"numberSizeInValue: %d", heightOfWebViewInt);
if (!alreadyUpdated) {
alreadyUpdated = YES;
[inspirationFeedTable reloadData];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < [sizeOfWebViewCell count] && [sizeOfWebViewCell count] != 0) {
NSNumber *numberValueOfHeight = [sizeOfWebViewCell objectAtIndex:indexPath.row];
int rowAtHeight = numberValueOfHeight.integerValue;
return rowAtHeight;
}
return 360;
}