gpt4 book ai didi

ios - 如何在 UITableView 的单元格中引用文本字段的文本

转载 作者:行者123 更新时间:2023-11-29 10:50:20 24 4
gpt4 key购买 nike

我对如何在 UITableView 中引用文本字段的文本感到非常困惑。我在一个没有文本的 TableView 中有 5 行,用户输入文本,然后将其保存为设置。我试图让数组 _textBox1Contents 和 _textBox2Contents 在 5 个 textBox1 和 textBox2 文本字段中包含用户输入的文本。如何引用特定单元格的文本字段,以便使用 NSUserDefaults 将它们发送到应用程序的其他部分?

提前致谢。

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

// Configure the cell...

long row = [indexPath row];

cell.image.image = [UIImage imageNamed:_image[row]];
cell.titleLabel.text = _Title[row];
cell.textbox1.placeholder = _textBox1[row];
cell.textbox2.placeholder = _textBox2[row];
cell.colon.text = _colon[row];

cell.textbox1.delegate = self;
cell.textbox2.delegate = self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;

_textBox1Contents = @[@"",
@"",
@"",
@"",
@"",];

_textBox2Contents = @[@"",
@"",
@"",
@"",
@"",];

return cell;
}

最佳答案

在您的 UITextField 上添加一个标签(比如说 100)。然后,在您的 cellForRowAtIndexPath 上执行

UITextField *textField = (UITextField *)[cell viewWithTag:100];
textField.text = [NSString stringWithFormat:@"%d",indexPath.row];

关于ios - 如何在 UITableView 的单元格中引用文本字段的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20728329/

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