Я пишу UITableView, который содержит 2 раздела.При первой загрузке таблицы все ячейки отображают правильную информацию, но когда я начинаю прокручивать вверх и вниз, ячейки detailsTelxtLabel и accessoryType обновляются неправильно, так что некоторые ячейки, которые должны содержать только подробныйTextLabel, также содержат аксессуар и ячейкидолжен содержать только аксессуар и содержать подробный текстовый ярлык.
Внутри cellForRowAtIndexPath:
Я использую вложенные операторы switch / case, чтобы применить правильные значения к ячейкам в соответствующем разделе / строке.Насколько я могу судить, логика в этих утверждениях верна, поэтому возможно ли, что значение переменной cell
неверно при обновлении?
Таблица загружается правильно, но после прокрутки accessoryType и detailsTextLabel перепутаны.
Нажмите для ссылки на снимки экрана таблицы.
Вот код внутри моего подкласса UITableViewController:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [sectionNames count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSArray *headingsSection = [cellTitles objectAtIndex:section];
return [headingsSection count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [sectionNames objectAtIndex:section];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.tableView.allowsSelection = YES;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[cellTitles objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
switch (indexPath.section) {
case 0:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d%%", [[assistSettingsArray_glob objectAtIndex:indexPath.row] intValue]];
break;
case 1:
switch (indexPath.row) {
case 0:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 1:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 2:
if (defaultAssistOn) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
break;
}
break;
}
return cell;
}