我在一行中放置了三个文本字段,在另一行中放置了 1 个文本字段。我将所有文本字段放在一个数组中,并在cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier ];
if (indexPath.row == 0) {
UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
tf.delegate = self;
tf.tag = 16;
tf.borderStyle = UITextBorderStyleRoundedRect;
[cell.contentView addSubview:tf];
[tf release];
UITextField *tf1 = [[UITextField alloc]initWithFrame:CGRectMake(150, 10, 100, 30)];
tf1.delegate = self;
tf1.tag = 17;
tf1.borderStyle = UITextBorderStyleRoundedRect;
[cell.contentView addSubview:tf1];
[tf1 release];
}
else {
UITextField *tf3 = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
tf3.delegate = self;
tf3.tag = 18;
tf3.borderStyle = UITextBorderStyleRoundedRect;
[cell.contentView addSubview:tf3];
[tf3 release];
}
}
UITextField *tf = (UITextField *)[cell.contentView viewWithTag:16];
tf.text = [m_textFieldArray objectAtIndex:indexPath.row];
UITextField *tf1 = (UITextField *)[cell.contentView viewWithTag:17];
tf1.text = [m_textFieldArray objectAtIndex:indexPath.row];
UITextField *tf3 = (UITextField *)[cell.contentView viewWithTag:18];
tf3.text = [m_textFieldArray objectAtIndex:indexPath.row];
// cell.textLabel.text = @"Hiiiii";
return cell;
}
并在textFieldDidEndEditing
方法中写如下。
[textFieldsDataArray replaceObjectAtIndex:currentIndexPath.row withObject:textField.text];
我的问题是,一旦我在一个文本字段中输入文本并上下滚动,那么相同的文本就会出现在同一行中剩余的两个文本字段中。
如果我在三个文本字段中输入文本然后滚动,那就是从最后一个文本字段中获取所有文本。