我有一个带有自定义文本视图的表格视图单元格,我现在想知道如何在编辑/添加文本后访问文本框中的文本。
当我通过 IB 绘制文本字段时,我通常会知道这是如何完成的,但我的 textviewcell 是动态绘制的。
(即我想捕获在detailLabel.text中更新的数据)
这是适应您的答案的相关代码。再次感谢!
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
//Big Text Box
UITextView *detailLabel = [[UITextView alloc] initWithFrame:CGRectMake(30, 80, 500, 150)];
detailLabel.tag = 20;
[cell.contentView addSubview:detailLabel];
detailLabel.layer.borderWidth = 1;
detailLabel.layer.borderColor = [[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.9] CGColor];
detailLabel.layer.cornerRadius = 10;
detailLabel.font = [UIFont fontWithName:@"Helvetica" size:17];
[detailLabel release];
}
UITextView * detailLabel = (UITextView *) [cell.contentView viewWithTag:20];
switch (indexPath.row) {
case 0:
detailLabel.text = @"no";
break;
default:
detailLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
detailLabel.hidden = NO;
}