gpt4 book ai didi

iphone - 根据WebView的内容使用WebView调整UITableViewCell的大小

转载 作者:行者123 更新时间:2023-12-01 18:27:38 24 4
gpt4 key购买 nike

我试图根据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;

}

最佳答案

请设置cell.feedWebView.tag = indexPath.row;

而不是indexPathIntValue = indexPath.row;

并且在webViewDidFinishLoading方法中请使用下面的行

[sizeOfWebViewCell insertObject:[NSNumber numberWithInt:heightOfWebViewInt] atIndex:webView.tag];

关于iphone - 根据WebView的内容使用WebView调整UITableViewCell的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11984875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com