gpt4 book ai didi

ios - 具有动态数据初始化的 UiTableviewCell 未正确加载

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

在我的单元格中,数据正在加载,但在我向下滚动之前它都是乱七八糟的,然后如果我向后滚动所有格式正确。因此,当我加载的每一个 uitableview 数据列表都被搞砸了,一旦我开始滚动并向上滚动,它就会到位并正确显示。请帮忙。

我的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
for(UIView *v in [cell subviews])
{
if([v isKindOfClass:[UILabel class]])
[v removeFromSuperview];
if ([v isKindOfClass:[UIImageView class]])
[v removeFromSuperview];
}
UIView *CellBGView = [[UIView alloc] initWithFrame:CGRectMake(10, 5, cell.frame.size.width-20, cell.frame.size.height-10)];
CellBGView.backgroundColor = [UIColor whiteColor];

UIImageView *divider = [[UIImageView alloc] initWithFrame:CGRectMake(CellBGView.frame.size.width-155, CellBGView.frame.size.height-140, 150, 150)];
divider.image = [UIImage imageNamed:@"icon_alpha.png"];
[CellBGView addSubview:divider];
......
return cell;
}

这是我打开列表时和滚动表格之前的输出

enter image description here

滚动后一切就绪

enter image description here

最佳答案

我有一个解决方案。

  • 首先,创建UITableViewCell的子类(例如,将其命名为DemoTableViewCell)

  • DemoTableViewCellinitWithStyle 方法中,将图像和标签添加到单元格。

  • cellForRowAtIndexPath 中,您不需要添加或删除图像和标签。只需为它们更改颜色或设置图像即可。

关于ios - 具有动态数据初始化的 UiTableviewCell 未正确加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47072766/

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