gpt4 book ai didi

ios - 管理 UITableviewCell 中的 View

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

编辑:更新代码以完成我想做的事情。

我有一个 TableView ,我想在其中动态地将 View 数组加载到行中。

例如,如果我的数组中有两个对象: {UITextField object, UIImage image} 我希望第一行显示文本字段,第二行显示图像。我不知道如何刷新/管理内容,这样它们就不会相互添加。当我滚动时,随着单元格在队列中重复使用,图像和文本字段会相互添加。

让我们假设我的项目数组称为 arrayOfItems 并包含我想要显示的文本字段或图像的列表。

根据下面的答案,下面的代码有效。

[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

for (id obj in [cell.contentView subviews]) {
[obj removeFromSuperview];
}

[cell.contentView addSubView:[self.arrayOfItems objectAtIndex:indexPath.row];

最佳答案

我认为你应该自定义两个不同的 UITableView Cell。

CellForRowAtIndexPath

NSInteger row = indexPath.row;
if(row%2 ==0){
// register your UITextField cell
}else{
// register your UIImage View cell
}

我认为这是一个更好的方法。

关于ios - 管理 UITableviewCell 中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20625413/

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