Custom UITableViewCell redraw issues
I have a custom UITableView cell that I've added a textbox to for editing, that shows and hides based on the edit mode. I've also tried adding a vertical line that shows when editing, and it does that, but I'm running into some drawing issues. I just added a green checkmark rightView to start working on input validation feedback, and I'm seeing similar issues.

Here is the code for the cell, and part of my cellForRowAtIndexPath.
    
    #import <UIKit/UIKit.h>
        
        @interface EditableCellStyle2 : UITableViewCell {
        	CGRect editRect;
        	UITextField *editField;
        	UIView *lineView;
        }
        
        @property (nonatomic, readonly, retain) UITextField *editField;
        @property (nonatomic, readonly, retain) UIView *lineView;
        
        @end

---

    #import "EditableCellStyle2.h"
    
    
    @implementation EditableCellStyle2
    
    @synthesize editField;
    @synthesize lineView;
    
    
    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // Initialization code.
    		editRect = CGRectMake(83, 12, self.contentView.bounds.size.width-83, 19);
    		
    		editField = [[UITextField alloc] initWithFrame:editRect];
    		editField.font = [UIFont boldSystemFontOfSize:15];
            editField.textAlignment = UITextAlignmentLeft;
            editField.textColor = [UIColor blackColor];
    		editField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
    		
    		[self.contentView addSubview:editField];
    		
    		self.editField.enabled = NO;
    		self.editField.hidden = YES;
    		
    		
    		lineView = [[UIView alloc] initWithFrame:CGRectMake(80, 0, 1, self.contentView.bounds.size.height)];
    		self.lineView.backgroundColor = [UIColor lightGrayColor];
    		[self.contentView addSubview:lineView];
    		self.lineView.hidden = YES;
    	}
        return self;
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        
        [super setSelected:selected animated:animated];
        
        // Configure the view for the selected state.
    }
    
    -(void)layoutSubviews
    {
    	[super layoutSubviews]; // layouts the cell as UITableViewCellStyleValue2 would normally look like
    	
    	editRect = CGRectMake(83, 12, self.contentView.frame.size.width-self.detailTextLabel.frame.origin.x-10, 19);
    	editField.frame = editRect;
    }
    
    
    - (void)willTransitionToState:(UITableViewCellStateMask)state {
    	[super willTransitionToState:state];
    	
    	if (state & UITableViewCellStateEditingMask) {
    		self.detailTextLabel.hidden = YES;
    		self.editField.enabled = YES;
    		self.lineView.hidden = NO;
    		self.editField.hidden = NO;
    	}
    }
    
    - (void)didTransitionToState:(UITableViewCellStateMask)state {
    	[super didTransitionToState:state];
    	
    	if (!(state & UITableViewCellStateEditingMask)) {
    		self.editField.enabled = NO;
    		self.editField.hidden = YES;
    		self.lineView.hidden = YES;
    		self.detailTextLabel.hidden = NO;
    		self.editField.text = self.detailTextLabel.text;
    	}
    }
    
    
    - (void)dealloc {
    	[editField release];
    	[lineView release];
    	
        [super dealloc];
    }
    
    
    @end

---


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
    	// handling every section by hand since this view is essentially static. Sections 0, 1, 2, and 4 use a generic editable cell.
    	// Section 3 uses the multiline address cell.
    	
        static NSString *CellIdentifier = @"Cell";
        
    	EditableCellStyle2 *cell = (EditableCellStyle2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    	
    	if (indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2 || indexPath.section == 4) {
    		if (cell == nil) {
    			cell = [[[EditableCellStyle2 alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    		}
    	}
    	
    	// Configure the Odometer
        if (indexPath.section == 0) {
    		NSArray *array = [sectionsArray objectAtIndex:indexPath.section];
    		NSDictionary *dictionary = [array objectAtIndex:indexPath.row];
    		
    		cell.textLabel.text = @"Odometer";
    		cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"Odometer"]];
    		cell.tag = kOdometer;
    		cell.editField.text = cell.detailTextLabel.text;
    		cell.editField.placeholder = @"Odometer";
    		cell.editField.tag = kOdometer;
    		cell.editField.keyboardType = UIKeyboardTypeNumberPad;
    		
    		// Create a view for the green checkmark for odometer input validation and set it as the right view.
    		UIImage *checkImage = [UIImage imageNamed:@"tick.png"];
    		UIImageView *checkImageView = [[[UIImageView alloc] initWithImage:checkImage] autorelease];
    		cell.editField.rightView = checkImageView;
    		cell.editField.rightViewMode = UITextFieldViewModeAlways;
    	}
    
    return cell;
    }

---

There is more to it but all the cells are built the same way.

The problems are that, when in edit mode, the vertical lines will display properly. When I leave edit mode, any cells that were off screen when I go to normal mode still have the vertical line (it doesn't get hidden). Also, now that I've added the imageView for the checkmark indicator, any cells that are off screen when switching modes gain the checkmark. (only section 0 sets it up).

I've also noticed that if i do cell.setNeedsDisplay, the text label and detail text label won't update if the data source has been updated. I have to do [self.tableView reloadData] which skips any active animations.

I'm sure these issues are related to me using a custom cell + dequeueReusableCellWithIdentifier, but I can't find exactly what.

Any feedback or a push in the right direction would be appreciated.
Custom UITableViewCell redraw issues
===

I have a custom UITableView cell that I've added a textbox to for editing, that shows and hides based on the edit mode. I've also tried adding a vertical line that shows when editing, and it does that, but I'm running into some drawing issues. I just added a green checkmark rightView to start working on input validation feedback, and I'm seeing similar issues.

Here is the code for the cell, and part of my cellForRowAtIndexPath.
    
    #import <UIKit/UIKit.h>
        
        @interface EditableCellStyle2 : UITableViewCell {
        	CGRect editRect;
        	UITextField *editField;
        	UIView *lineView;
        }
        
        @property (nonatomic, readonly, retain) UITextField *editField;
        @property (nonatomic, readonly, retain) UIView *lineView;
        
        @end

---

    #import "EditableCellStyle2.h"
    
    
    @implementation EditableCellStyle2
    
    @synthesize editField;
    @synthesize lineView;
    
    
    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // Initialization code.
    		editRect = CGRectMake(83, 12, self.contentView.bounds.size.width-83, 19);
    		
    		editField = [[UITextField alloc] initWithFrame:editRect];
    		editField.font = [UIFont boldSystemFontOfSize:15];
            editField.textAlignment = UITextAlignmentLeft;
            editField.textColor = [UIColor blackColor];
    		editField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
    		
    		[self.contentView addSubview:editField];
    		
    		self.editField.enabled = NO;
    		self.editField.hidden = YES;
    		
    		
    		lineView = [[UIView alloc] initWithFrame:CGRectMake(80, 0, 1, self.contentView.bounds.size.height)];
    		self.lineView.backgroundColor = [UIColor lightGrayColor];
    		[self.contentView addSubview:lineView];
    		self.lineView.hidden = YES;
    	}
        return self;
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        
        [super setSelected:selected animated:animated];
        
        // Configure the view for the selected state.
    }
    
    -(void)layoutSubviews
    {
    	[super layoutSubviews]; // layouts the cell as UITableViewCellStyleValue2 would normally look like
    	
    	editRect = CGRectMake(83, 12, self.contentView.frame.size.width-self.detailTextLabel.frame.origin.x-10, 19);
    	editField.frame = editRect;
    }
    
    
    - (void)willTransitionToState:(UITableViewCellStateMask)state {
    	[super willTransitionToState:state];
    	
    	if (state & UITableViewCellStateEditingMask) {
    		self.detailTextLabel.hidden = YES;
    		self.editField.enabled = YES;
    		self.lineView.hidden = NO;
    		self.editField.hidden = NO;
    	}
    }
    
    - (void)didTransitionToState:(UITableViewCellStateMask)state {
    	[super didTransitionToState:state];
    	
    	if (!(state & UITableViewCellStateEditingMask)) {
    		self.editField.enabled = NO;
    		self.editField.hidden = YES;
    		self.lineView.hidden = YES;
    		self.detailTextLabel.hidden = NO;
    		self.editField.text = self.detailTextLabel.text;
    	}
    }
    
    
    - (void)dealloc {
    	[editField release];
    	[lineView release];
    	
        [super dealloc];
    }
    
    
    @end

---


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
    	// handling every section by hand since this view is essentially static. Sections 0, 1, 2, and 4 use a generic editable cell.
    	// Section 3 uses the multiline address cell.
    	
        static NSString *CellIdentifier = @"Cell";
        
    	EditableCellStyle2 *cell = (EditableCellStyle2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    	
    	if (indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2 || indexPath.section == 4) {
    		if (cell == nil) {
    			cell = [[[EditableCellStyle2 alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    		}
    	}
    	
    	// Configure the Odometer
        if (indexPath.section == 0) {
    		NSArray *array = [sectionsArray objectAtIndex:indexPath.section];
    		NSDictionary *dictionary = [array objectAtIndex:indexPath.row];
    		
    		cell.textLabel.text = @"Odometer";
    		cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"Odometer"]];
    		cell.tag = kOdometer;
    		cell.editField.text = cell.detailTextLabel.text;
    		cell.editField.placeholder = @"Odometer";
    		cell.editField.tag = kOdometer;
    		cell.editField.keyboardType = UIKeyboardTypeNumberPad;
    		
    		// Create a view for the green checkmark for odometer input validation and set it as the right view.
    		UIImage *checkImage = [UIImage imageNamed:@"tick.png"];
    		UIImageView *checkImageView = [[[UIImageView alloc] initWithImage:checkImage] autorelease];
    		cell.editField.rightView = checkImageView;
    		cell.editField.rightViewMode = UITextFieldViewModeAlways;
    	}
    
    return cell;
    }

---

There is more to it but all the cells are built the same way.

The problems are that, when in edit mode, the vertical lines will display properly. When I leave edit mode, any cells that were off screen when I go to normal mode still have the vertical line (it doesn't get hidden). Also, now that I've added the imageView for the checkmark indicator, any cells that are off screen when switching modes gain the checkmark. (only section 0 sets it up).

I've also noticed that if i do cell.setNeedsDisplay, the text label and detail text label won't update if the data source has been updated. I have to do [self.tableView reloadData] which skips any active animations.

I'm sure these issues are related to me using a custom cell + dequeueReusableCellWithIdentifier, but I can't find exactly what.

Any feedback or a push in the right direction would be appreciated.