UITableViewCell中的UITextField在滚动时被删除

时间:2011-02-04 00:02:38

标签: iphone ios uitableview uitextfield

我在分组的UITableView中有一个小表单(5个字段)。每个UITextField都在UITableView单元格内。当单击textField时,它会弹出键盘,然后允许您将某些单元格滚出视图,当您将它们拉回时,它们的内容将被删除。

我认为他们已经重绘了,所以他们的内容消失了吗?如果是这样,防止这种情况的最佳方法是什么?由于我只有5个字段,当滚动回到视图时,是否必须重新绘制单元格?

我正在重复使用细胞:

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

    }

1 个答案:

答案 0 :(得分:5)

您可以拥有单独的文本字段数组,并按照以下方式实现单元格创建回调:

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath 
{
   static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

    }
    [[cell.contentView subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];

    [cell.contentView addSubview: [textFieldsArray objectsAtIndex: indexPath.row]];

    return cell;

} 
相关问题