gpt4 book ai didi

objective-c - 每个 tableviewcells 中的 uiwebview

转载 作者:行者123 更新时间:2023-11-29 11:09:57 25 4
gpt4 key购买 nike

我需要在我的 Uitableview 的每个 tableviewcell 中显示每个 webview。当使用下面的代码时,当有 2 个元素时,第一个单元格是空的,但第二个单元格是正确的。

小时和hrsHtml 包含所有值,问题是只有最后一个数据显示在 tableview 中相应的单元格中。其他单元格只是空白。

还有总单元格是 2,首先我们只能看到仅第二个单元格,但在滚动 tableview 后重新加载并且第二个单元格消失并显示第一个单元格。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [brId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

}
cell.selectionStyle = UITableViewCellSelectionStyleNone;

[cell.contentView addSubview:hrs];

hrsHtml = [NSString stringWithFormat:@" <font size=\"2\" face=\"Arial\">%@ </font>",[html objectAtIndex:indexPath.row]];

[hrs loadHTMLString:hrsHtml baseURL:nil];

return cell;
}

出现tableview时的截图,只有单元格2中的webview

enter image description here

tableview滚动时的截图,cell 1只有webview,cell 2消失

enter image description here

最佳答案

由于 hrshrsHtml 是单个对象,因此即使您有多个单元格,您也只有一个。如果您修改 hrs,所有单元格都会更改,因为它们似乎正在共享它。 (除非您在某处有其他代码可以更改这些变量指向的对象。)

另一件奇怪的事情是,您使用 brId 数组来确定行数,并使用 html 数组来获取行内容。如果这些不同步,您就会遇到问题。

此外,您应该只在创建新单元格时将 subview 添加到单元格。

关于objective-c - 每个 tableviewcells 中的 uiwebview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12004717/

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