我有一个可用的视图2行n 4个部分,我在每个单元中有一个标签和文本字段。问题是我的标签出现在所有部分,因为我的文本字段在其他部分不重复。实际上,每个单元格都有两个textfield单元格,一个是普通文本框,另一个是拾取器文本框(当我单击TF时,拾取器会弹出)。 对于一个部分TF都会出现,但不会在其他部分中重复。在uitableview问题中的两个Textfield问题
我的代码
static NSString *CellIdentifier = @"Cell";
UITextField *textField;
NSString *string=[NSString stringWithFormat:@"ident_%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UILabel *lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(50, 10, 100, 35)];
[lbl1 setFont:[UIFont systemFontOfSize:16]];
[lbl1 setTextColor:[UIColor blackColor]];
[lbl1 setBackgroundColor:[UIColor clearColor]];
if (indexPath.row==0) {
lbl1.text = @"Quantity";
[cell.contentView addSubview:self.qntTF];
}
if (indexPath.row==1) {
lbl1.text = @"Unit";
[cell.contentView addSubview:self.unitTF];
}
// Configure the cell...;
textField =[self.tableArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:textField];
cell.textLabel.text = nil;
textField.tag = TextFieldTag;
cell.detailTextLabel.text = nil;
[cell addSubview:lbl1];
[lbl1 release];
return cell;
嗨 - 请再看看我的答案。那里的模式将解决你的问题。你添加了太多的标签(每次单元格被绘制时都会添加一个),并且你还一遍又一遍地添加相同的文本字段。因为它是一样的,它只是从一个单元移动到另一个单元。你只会在被调用最后渲染的单元上看到它。 – danh 2012-07-31 14:06:28
@danh我试过了,现在问题是什么问题,它没有得到所有的单元格被称为只有两个部分,1保留空标签,而不是texfield。我的选择器现在创建问题 – 2012-08-01 05:37:27