UITableViewCell里面的UITextField被滚动删除

UITableViewCell里面的UITextField被滚动删除

问题描述:

我在一个分组的UITableView中有一个小表单(5个字段)。每个UITextField都在一个UITableView单元内。点击textField时,会弹出键盘,然后您可以将某些单元格向外滚动,当您将它们拉下时,其内容将被删除。UITableViewCell里面的UITextField被滚动删除

我正确地假设他们已被重新绘制,所以他们的内容不见了?如果是这样,防止这种情况的最好方法是什么?由于我只有5个字段,当滚动到视图中时,是否必须重绘我的单元格?

我重用细胞:

static NSString *CellIdentifier = @"Cell"; 

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

    } 

你可以有你的文本字段的一个单独的数组并实现您创建细胞回调是这样的:

-(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; 

}