我創建了至少10個單元格,每個單元格上都有UITextField,用於註冊頁面。當我在第一個單元格的文本字段中插入單詞時,以及當我滾動tableView時,位於另一個單元格中的文本字段顯示我剛輸入的單詞。TableView單元格中的UITextField顯示問題
以下是我的代碼。我輸入的textField數據是循環的,這是由dequeueReusableCellWithIdentifier引起的......我該如何解決這個問題?非常感謝你。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"RCell";
RegisterCell *cell = (RegisterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[RegisterCell alloc] initWithFrame:CGRectMake(0, 0, 280, 44) reuseIdentifier:CellIdentifier] autorelease];
if(indexPath.section == 0){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]];
NSString *mainLabel = [NSString stringWithFormat:@"%@", [rowData objectForKey:@"regisLbl"]];
cell.registerLabel.text = mainLabel;
UITextField *valTxtField = [[UITextField alloc] initWithFrame:CGRectMake(120, 5, 180, 30)];
valTxtField.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:18.0];
valTxtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
valTxtField.delegate = self;
valTxtField.returnKeyType = UIReturnKeyDone;
valTxtField.autocorrectionType = UITextAutocorrectionTypeNo;
valTxtField.autocapitalizationType = UITextAutocapitalizationTypeNone;
if(indexPath.row == 0)
{
valTxtField.text = @"";
emailTxtFld = valTxtField; //emailTxtFld is global variable
}
if(indexPath.row == 1)
{
valTxtField.text = @"";
reEmailTxtFld = valTxtField; //reEmailTxtFld is global variable
}
[cell.contentView addSubview:valTxtField];
[valTxtField release];
}
else if(indexPath.section == 1){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]+10];
NSString *mainLabel = [NSString stringWithFormat:@"%@", [rowData objectForKey:@"regisLbl"]];
cell.registerLabel.text = mainLabel;
cell.registerTextField.enabled = NO;
}
else if(indexPath.section == 2){
if(indexPath.row == 0){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]+11];
NSString *mainLabel = [NSString stringWithFormat:@"%@", [rowData objectForKey:@"regisLbl"]];
cell.registerLabel.text = mainLabel;
cell.registerTextField.enabled = NO;
}
}
return cell;
}