Scrolling issue in uitableview having textfields
I have a tableview with multiple sections and each has two rows containing the **label and the textfield**.While scrolling the data in the textfield changes the position.




  [1]: http://stackoverflow.com/questions/7482289/uitableview-scrolling-issue  This question has the similar problem as mine but i couldn't get the exact solution.

This is my data source i.e cellForAtIndexPath method.
    
    
    static NSString *CellIdentifier = @"Cell";
    
  
    
    UILabel *   mainLabel;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
    if (cell == nil) {
                
        
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        
        cell.accessoryType = UITableViewCellAccessoryNone;
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    
        
        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(20.0, 8.0, 100.0, 30.0)] autorelease];
        
        mainLabel.tag = MAINLABEL_TAG;
        
        mainLabel.font = [UIFont systemFontOfSize:17.0];
        
        
        mainLabel.textColor = [UIColor blackColor];
        
        mainLabel.backgroundColor = [UIColor clearColor];
      
        
        [cell.contentView addSubview:mainLabel];
        
        mainTF = [[[UITextField alloc]initWithFrame:CGRectMake(150, 8.0, 140.0, 30)] autorelease];
        
        mainTF.tag = MAINTEXTFIELD_TAG;
        
        mainTF.font = [UIFont systemFontOfSize:17.0];
        
        mainTF.textColor = [UIColor blackColor];
        
        mainTF.backgroundColor = [UIColor clearColor];
        
        mainTF.borderStyle = UITextBorderStyleRoundedRect;
        
        mainTF.delegate = self;
        
        mainTF.autocorrectionType = UITextAutocorrectionTypeNo;
        
        mainTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        
        mainTF.returnKeyType = UIReturnKeyDone;
        
        mainTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        mainTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        [cell.contentView addSubview:mainTF];
        
    }
    
    else{
        
        
        mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
        
        mainTF = (UITextField *)[cell.contentView viewWithTag:MAINTEXTFIELD_TAG];
    }
    
    
    if (indexPath.row == 0) {
        
        mainLabel.text = @"Quantity";
        
        //mainTF.text =@"1";
    }
    else{
        
        mainLabel.text = @"Unit";
        
        //mainTF.text = @"100 grams";
    }
    
    // Configure the cell...
    
    return cell;
}


Scrolling issue in uitableview having textfields
===

I have a tableview with multiple sections and each has two rows containing the **label and the textfield**.While scrolling the data in the textfield changes the position.




  [1]: http://stackoverflow.com/questions/7482289/uitableview-scrolling-issue  This question has the similar problem as mine but i couldn't get the exact solution.

This is my data source i.e cellForAtIndexPath method.
    
    
    static NSString *CellIdentifier = @"Cell";
    
  
    
    UILabel *   mainLabel;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
    if (cell == nil) {
                
        
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        
        cell.accessoryType = UITableViewCellAccessoryNone;
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    
        
        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(20.0, 8.0, 100.0, 30.0)] autorelease];
        
        mainLabel.tag = MAINLABEL_TAG;
        
        mainLabel.font = [UIFont systemFontOfSize:17.0];
        
        
        mainLabel.textColor = [UIColor blackColor];
        
        mainLabel.backgroundColor = [UIColor clearColor];
      
        
        [cell.contentView addSubview:mainLabel];
        
        mainTF = [[[UITextField alloc]initWithFrame:CGRectMake(150, 8.0, 140.0, 30)] autorelease];
        
        mainTF.tag = MAINTEXTFIELD_TAG;
        
        mainTF.font = [UIFont systemFontOfSize:17.0];
        
        mainTF.textColor = [UIColor blackColor];
        
        mainTF.backgroundColor = [UIColor clearColor];
        
        mainTF.borderStyle = UITextBorderStyleRoundedRect;
        
        mainTF.delegate = self;
        
        mainTF.autocorrectionType = UITextAutocorrectionTypeNo;
        
        mainTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        
        mainTF.returnKeyType = UIReturnKeyDone;
        
        mainTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        mainTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        [cell.contentView addSubview:mainTF];
        
    }
    
    else{
        
        
        mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
        
        mainTF = (UITextField *)[cell.contentView viewWithTag:MAINTEXTFIELD_TAG];
    }
    
    
    if (indexPath.row == 0) {
        
        mainLabel.text = @"Quantity";
        
        //mainTF.text =@"1";
    }
    else{
        
        mainLabel.text = @"Unit";
        
        //mainTF.text = @"100 grams";
    }
    
    // Configure the cell...
    
    return cell;
}

