Проблема, с которой я сталкиваюсь, заключается в том, что когда я просматриваю свое табличное представление, если текстовые поля пустые (и показывает значение-заполнитель), строки показывают, что соответствующее значение-заполнитель просто отлично. Однако, если я начну просматривать представление таблицы и вводить текст внутри текстовых полей, как только я прокручу вниз, предыдущие значения текстового поля начнут отображаться в других текстовых полях ниже в таблице. Я предполагаю, что это имеет какое-то отношение к идентификатору ячейки, но, похоже, это отлично работает с моими ярлыками и заполнителем uitextfield, а не текстовым вводом текста текстового поля. Есть предположения? Вот код ...Текстовое поле в ячейке tableview изменяет текстовое значение
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.headerLabel.text = @"some string";
cell.textField.placeholder = @"some other string placeholder,";
cell.textField.delegate = self;
return cell;
}
А вот CustomCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
headerLabel =[[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.translatesAutoresizingMaskIntoConstraints = NO;
headerLabel.textColor = [UIColor colorWithRed:155.0/255.0 green:155.0/255.0 blue:155.0/255.0 alpha:1.0];
headerLabel.font = [UIFont fontWithName:@"Helvetica Neue Reg" size:15];
textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.textColor = [UIColor colorWithRed:13.0/255.0 green:122/255.0 blue:255.0/255.0 alpha:1.0];
textField.translatesAutoresizingMaskIntoConstraints = NO;
textField.font = [UIFont fontWithName:@"Helvetica Neue" size:15];
[self.contentView addSubview:headerLabel];
[self.contentView addSubview:textField];
[self.contentView addConstraint: [NSLayoutConstraint constraintWithItem:headerLabel
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeLeading
multiplier:1
constant:27 ] ] ;
[self.contentView addConstraint: [NSLayoutConstraint constraintWithItem:headerLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeTop
multiplier:1
constant:10 ] ] ;
[self.contentView addConstraint: [NSLayoutConstraint constraintWithItem:textField
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeLeading
multiplier:1
constant:27 ] ] ;
[self.contentView addConstraint: [NSLayoutConstraint constraintWithItem:textField
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:headerLabel
attribute:NSLayoutAttributeBottom
multiplier:1
constant:5 ] ] ;
[self.contentView addConstraint: [NSLayoutConstraint constraintWithItem:textField
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:-27 ] ] ;
}
return self;
}
Вам нужно сохранить текст, как он меняется, и вы должны установить каждый текст поле 'text' в методе' cellForRowAtIndexPath: '. – rmaddy