我有一個可用的視圖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