Iphone 在我的UITableView中滚动时,返回时隐藏的行会很奇怪

Iphone 在我的UITableView中滚动时,返回时隐藏的行会很奇怪,iphone,objective-c,ios,cocoa-touch,ipad,Iphone,Objective C,Ios,Cocoa Touch,Ipad,我的UITableView遇到了一些奇怪的问题。 我有一个分组的TableView,每个部分有一行。每行中都有一个文本字段。 当我没有被迫滚动时,所有内容都显示正确 但是如果我必须滚动,以前隐藏的单元格就会被弄乱。它们确实包含一个文本字段,但有许多文本标签相互覆盖 有什么建议吗 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { stat

我的UITableView遇到了一些奇怪的问题。 我有一个分组的TableView,每个部分有一行。每行中都有一个文本字段。 当我没有被迫滚动时,所有内容都显示正确

但是如果我必须滚动,以前隐藏的单元格就会被弄乱。它们确实包含一个文本字段,但有许多文本标签相互覆盖

有什么建议吗

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

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

// Configure the cell...
if(indexPath.section < [sectionArray count]) {
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10,580, 31)];
    textField.tag = indexPath.section + 22;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    textField.delegate = self;
    textField.text = [item.rechnerValues objectAtIndex:indexPath.section+1];

    [cell.contentView addSubview:textField];
}
return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
}
//配置单元格。。。
if(indexPath.section<[sectionArray count]){

UITextField*textField=[[UITextField alloc]initWithFrame:CGRectMake(2010580,31)]; textField.tag=indexPath.section+22; textField.autocorrectionType=UITextAutocorrectionTypeNo; textField.autocapitalizationType=UITextAutocapitalizationTypeNone; textField.delegate=self; textField.text=[item.rechnerValues objectAtIndex:indexath.section+1]; [cell.contentView addSubview:textField]; } 返回单元; }
这是因为您正在重用单元格。因此,以前创建的
textFields
不会被删除。当你滚动的时候,你正在一个接一个地添加新的

解决方案:

  • 删除以前创建的
    textFields
  • (更好)只需将适当的
    文本设置为已创建的文本字段

  • 这是因为您正在重用单元。因此,以前创建的
    textFields
    不会被删除。当你滚动的时候,你正在一个接一个地添加新的

    解决方案:

  • 删除以前创建的
    textFields
  • (更好)只需将适当的
    文本设置为已创建的文本字段
  • -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
    静态NSString*CellIdentifier=@“Cell”;
    UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    如果(单元格==nil){
    cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
    
    UITextField*textField=[[UITextField alloc]initWithFrame:CGRectMake(2010580,31)]; textField.tag=indexPath.section+22; textField.autocorrectionType=UITextAutocorrectionTypeNo; textField.autocapitalizationType=UITextAutocapitalizationTypeNone; textField.delegate=self; textField.text=[item.rechnerValues objectAtIndex:indexath.section+1]; [cell.contentView addSubview:textField]; [文本字段发布]; } 否则{ //配置单元格。。。 if(indexPath.section<[sectionArray count]){ UITextField*textFld=(UITextField*)[cell.contentView视图带标记:indexPath.section+22]; 如果(textFld){ textFld.text=[item.rechnerValues objectAtIndex:indexath.section+1]; } } } 返回单元; }
    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
    静态NSString*CellIdentifier=@“Cell”;
    UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    如果(单元格==nil){
    cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
    
    UITextField*textField=[[UITextField alloc]initWithFrame:CGRectMake(2010580,31)]; textField.tag=indexPath.section+22; textField.autocorrectionType=UITextAutocorrectionTypeNo; textField.autocapitalizationType=UITextAutocapitalizationTypeNone; textField.delegate=self; textField.text=[item.rechnerValues objectAtIndex:indexath.section+1]; [cell.contentView addSubview:textField]; [文本字段发布]; } 否则{ //配置单元格。。。 if(indexPath.section<[sectionArray count]){ UITextField*textFld=(UITextField*)[cell.contentView视图带标记:indexPath.section+22]; 如果(textFld){ textFld.text=[item.rechnerValues objectAtIndex:indexath.section+1]; } } } 返回单元; }
    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    静态NSString*CellIdentifier=@“Cell”;
    UITextField*textField;
    UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    如果(单元格==nil){
    cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
    if(indexPath.section<[sectionArray count]){
    textField=[[UITextField alloc]initWithFrame:CGRectMake(2010580,31)];
    textField.tag=indexPath.section+22;
    textField.autocorrectionType=UITextAutocorrectionTypeNo;
    textField.autocapitalizationType=UITextAutocapitalizationTypeNone;
    textField.delegate=self;
    [cell.contentView addSubview:textField];
    [文本字段发布];
    }
    }
    否则{
    textField=(id)[cell.contentView-viewWithTag:indexPath.section+22];
    }
    textField.text=[item.rechnerValues objectAtIndex:indexath.section+1];
    //配置单元格。。。
    返回单元;
    
    }

    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    静态NSString*CellIdentifier=@“Cell”;
    UITextField*textField;
    UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    如果(单元格==nil){
    单元格=[[
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
    
            UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10,580, 31)];
            textField.tag = indexPath.section + 22;
            textField.autocorrectionType = UITextAutocorrectionTypeNo;
            textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
            textField.delegate = self;
            textField.text = [item.rechnerValues objectAtIndex:indexPath.section+1];
    
            [cell.contentView addSubview:textField];
    
            [textField release];
    
        }
        else{
                // Configure the cell...
            if(indexPath.section < [sectionArray count]) {
    
                UITextField *textFld=(UITextField*)[cell.contentView viewWithTag:indexPath.section + 22];
    
                if(textFld){
    
                    textFld.text=[item.rechnerValues objectAtIndex:indexPath.section+1];
    
                }            
    
    
    
            }
        }
        return cell;
    }
    
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {     
         static NSString *CellIdentifier = @"Cell";
       UITextField *textField;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
        if(indexPath.section < [sectionArray count]) {
            textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10,580, 31)];
            textField.tag = indexPath.section + 22;
            textField.autocorrectionType = UITextAutocorrectionTypeNo;
            textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
            textField.delegate = self;
            [cell.contentView addSubview:textField];
            [textField release];
        }
    }
    else {
           textField = (id)[cell.contentView viewWithTag:indexPath.section+22];
    }
    
        textField.text = [item.rechnerValues objectAtIndex:indexPath.section+1];
    
        // Configure the cell...
    
    
    return cell;