gpt4 book ai didi

iphone - UITableView 单元格/数据消失

转载 作者:行者123 更新时间:2023-12-01 19:27:52 25 4
gpt4 key购买 nike

我有一个分段的 tableView 加载所有部分的所有单元格中的所有数据。
每个单元格中有一个文本字段。

表格 View 不完全适合 iPad 屏幕,我无法访问所有不可见的单元格以读取/保存数据。当我在“textField”中进行更改时,然后向上滚动,向下滚动,所有更改都消失了。

我需要加载所有单元格,甚至一次不可见,才能访问它们。

对不起,我几天前才开始使用表格...
我认为这个问题与可重复使用的细胞有关,但不知道如何解决。

请寻求您的帮助。

初始化:

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

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];


if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400, 30)] ;
textField.enabled = NO;
cell.accessoryView = textField;
[textField release];

}
UITextField *textField = (UITextField*)cell.accessoryView;

if(indexPath.section == 0)
cell.textLabel.text = [idenInfo objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
cell.textLabel.text = [prodInfo objectAtIndex:indexPath.row];
else if (indexPath.section == 2)
cell.textLabel.text = [visInfo objectAtIndex:indexPath.row];


if(indexPath.section == 0)
textField.text = [idenInfoRez objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
textField.text = [prodInfoRez objectAtIndex:indexPath.row];
else if (indexPath.section == 2)
textField.text = [visInfoRez objectAtIndex:indexPath.row];

textField = nil;

return cell;
}

最佳答案

首先:您不必加载所有单元格,包括不可见的单元格。这就是 UITableView 和 MVC 模式的重点:将 View 与数据分开。

当用户更改文本字段中的值时,您要做的是更新您的数据源(即 idenInfoRezprodInfoRezvizInfoRez 在您的情况下)。因此,您必须将 UIViewController 设置为每个文本字段的委托(delegate),并在用户输入时更新值。

关于iphone - UITableView 单元格/数据消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5648191/

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