作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对如何在 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/
我是一名优秀的程序员,十分优秀!