In iOS 6 now they reuse the cells, but i dont want it too because it erases my data in the cells. the cells are all custom. They have UITextFields in them, but when i scroll up it adds another on top. heres how im registering: [SettingsTable registerClass:[TextFieldTableCell class] forCellReuseIdentifier:@"textFieldCell"];
and heres the code in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,
TextFieldTableCell *textFieldCell = (TextFieldTableCell *)[tableView dequeueReusableCellWithIdentifier:@"textFieldCell"];
[textFieldCell textFieldWithLabel];
textFieldCell.textLabel.text = @"Homepage";
textFieldCell.textLabel.backgroundColor = [UIColor clearColor];
textFieldCell.accessoryType = UITableViewCellAccessoryNone;
[textFieldCell sendSubviewToBack:textFieldCell.textLabel];
textFieldCell.textField.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"Homepage"];
textFieldCell.textField.returnKeyType = UIReturnKeyDone;
[textFieldCell.textField addTarget:self action:@selector(dismissHomepageKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];
here is the code in the UITableViewCell subclass,
header:
@interface TextFieldTableCell : UITableViewCell {
UITextField *textField;
}
@property (nonatomic, retain) UITextField *textField;
-(void)fullTextField;
-(void)textFieldWithLabel;
@end
main:
`@implementation TextFieldTableCell
@synthesize textField;
-(void)fullTextField {
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, 295, 43)];
self.textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.contentView addSubview:self.textField];
}
-(void)textFieldWithLabel {
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(123, 0, 177, 43)];
self.textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.contentView addSubview:self.textField];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(NSString*)reuseIdentifier {
return @"textFieldCell";
}
@end`
how can i fix to only have it called one since every time i scroll it resets it to default? and if i check if something in the cell is nil, like the textfield "no index path for table cell being reused" but in 1 view controller, with the same code just different place of getting the textfields initial text, it will work the way all should