我正在尝试根据 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;
}