У меня есть tableView с ячейками, содержащими один UITextField в качестве подпредставления для каждой ячейки. Моя проблема в том, что при прокрутке вниз текст в первой ячейке дублируется в последней ячейке. Я не могу на всю жизнь, если я пойму, почему. Я попытался загрузить ячейки из разных перьев, имея textFields как ivars. UITextFields, похоже, не является проблемой, я думаю, это как-то связано с повторным использованием tableView ячеек.
Все текстовые поля имеют источник данных, который отслеживает текст в текстовом поле, и текст сбрасывается при каждом отображении ячейки.
Есть идеи? Буду очень признателен за ответы на этот вопрос.
ОБНОВЛЕНИЕ 2:
Это код, который у меня есть для пользовательской ячейки, называемой JournalCell. Очень ценю обратную связь.
У меня 8 секций по 1 строке в каждой. Первые 7 содержат текстовое поле, а последняя представляет собой ячейку, действующую как кнопка.
Я проверяю ячейку кнопки, если она совпадает с разделом (7), то она возвращает эту ячейку, если нет, она продолжает до остальных. Может ли это быть так?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Section %i, Row %i", indexPath.section, indexPath.row);
if (indexPath.section == 7) {
static NSString *ButtonCellIdentifier = @"ButtonCellIdentifier";
UITableViewCell *buttonCell = [self.tableView dequeueReusableCellWithIdentifier:ButtonCellIdentifier];
if (buttonCell == nil) {
buttonCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ButtonCellIdentifier] autorelease];
buttonCell.selectionStyle = UITableViewCellSelectionStyleBlue;
buttonCell.accessoryType = UITableViewCellAccessoryNone;
buttonCell.textLabel.text = sClearAll;
buttonCell.textLabel.textAlignment = UITextAlignmentCenter;
buttonCell.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8];
buttonCell.textLabel.backgroundColor = [UIColor clearColor];
}
return buttonCell;
}
static NSString *TextCellIdentifier = @"JournalCellIdentifier";
JournalCell *cell = (JournalCell *)[self.tableView dequeueReusableCellWithIdentifier:TextCellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"JournalCell" owner:self options:nil];
cell = customCell;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
cell.textField.returnKeyType = UIReturnKeyNext;
cell.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0:
cell.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.authorTextField = cell.textField;
self.authorTextField.text = [self.textFieldDictionary objectForKey:@"author"];
NSLog(@"Reading Author:%@", [self.textFieldDictionary objectForKey:@"author"]);
break;
}
break;
case 1:
switch (indexPath.row) {
case 0:
self.yearTextField = cell.textField;
self.yearTextField.text = [self.textFieldDictionary objectForKey:@"year"];
NSLog(@"Reading Year:%@", [self.textFieldDictionary objectForKey:@"year"]);
break;
}
break;
case 2:
switch (indexPath.row) {
case 0:
self.volumeTextField = cell.textField;
self.volumeTextField.text = [self.textFieldDictionary objectForKey:@"volume"];
NSLog(@"Reading Volume:%@", [self.textFieldDictionary objectForKey:@"volume"]);
break;
}
break;
case 3:
switch (indexPath.row) {
case 0:
self.articleTextField = cell.textField;
self.articleTextField.text = [self.textFieldDictionary objectForKey:@"article"];
NSLog(@"Reading Article:%@", [self.textFieldDictionary objectForKey:@"article"]);
break;
}
break;
default:
break;
}
return cell;
}