У меня есть вид настроек с 3 разделами.Некоторые ячейки имеют разные стили: по умолчанию или значение1.Когда я быстро проведу пальцем вверх или вниз или изменим вид и вернусь, текст, который должен находиться в ячейке (например, detailTextLabel в моей ячейке с StyleValue1), либо больше не находится здесь, либо иногда в ячейке выше или ниже ..Вот скриншоты: первое - это нормальное состояние, второе - detailTextLabel из версии переместилось в ячейку выше, а в третьем исчезла система измерения detailTextLabel ...
![enter image description here](https://i.stack.imgur.com/LqJmJ.png)
А вот мой код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if (indexPath.section == 1 && indexPath.row == 0) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
else if (indexPath.section == 2 && indexPath.row == 2) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
else {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
}
// Selection style.
cell.selectionStyle = UITableViewCellSelectionStyleGray;
// Vehicles cells.
if (indexPath.section == 0 && indexPath.row < [self.userCarsArray count]) {
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.text = [[NSString stringWithFormat:@"%@ %@ %@",
[[self.userCarsArray objectAtIndex:indexPath.row] year],
[[self.userCarsArray objectAtIndex:indexPath.row] make],
[[self.userCarsArray objectAtIndex:indexPath.row] model]] uppercaseString];
// Checkmark if current car.
if ([[EcoAppAppDelegate userCar] idCar] == [[self.userCarsArray objectAtIndex:indexPath.row] idCar]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
selectedCarPath = indexPath;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
// Add car cell.
if (indexPath.section == 0 && indexPath.row == [self.userCarsArray count]) {
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.text = @"Add Vehicle";
}
// General cells.
if (indexPath.section == 1 && indexPath.row == 0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"Measurement System";
cell.textLabel.textColor = [UIColor darkGrayColor];
if ([EcoAppAppDelegate measurement] == MeasurementTypeMile)
cell.detailTextLabel.text = @"Miles";
else
cell.detailTextLabel.text = @"Meters";
}
// Information cells.
if (indexPath.section == 2 && indexPath.row == 0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"About";
cell.textLabel.textColor = [UIColor darkGrayColor];
}
if (indexPath.section == 2 && indexPath.row == 1) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"License";
cell.textLabel.textColor = [UIColor darkGrayColor];
}
if (indexPath.section == 2 && indexPath.row == 2) {
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = @"Version";
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.detailTextLabel.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
Знаете ли вы, как я могу решить эту проблему?Спасибо!