gpt4 book ai didi

iphone - 自定义单元的重复使用

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

我采用了自定义单元格,并且没有重复使用那里的标识符。我在使用自定义单元格的 TableView 中使用标识符。但是,当我运行我的应用程序并在文本字段中输入数据时,当我 ScrollView 时,我的数据会被删除。并且我的单元格不会重用该数据。任何人都可以帮助我解决这件事。谢谢!

自定义单元格代码

-(UITableViewCell *)returnCellForEach:(UITableView *)tableView
{
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

myLabel = (UILabel *)[customCell.contentView viewWithTag:10];

return customCell;
}

TableView “cellForRowAtIndexPath”代码

static NSString *CellIdentifier = @"Cell";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Hello"] autorelease];
}

这件事有什么错误。谢谢!

最佳答案

单元格不应用于存储您的数据。如果用户在编辑字段中输入内容,您需要将内容复制到例如 View Controller 中的成员变量。如果单元格滚动到 View 之外,它要么被破坏,要么可能被保留以供重复使用。无论哪种方式,您都不能再依赖该编辑字段的存在。

关于iphone - 自定义单元的重复使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306396/

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