我有一个包含 3 个部分的设置视图。某些单元格具有不同的样式:默认或 Value1。当我快速向上或向下滑动,或更改视图并返回时,应该在单元格中的文本(例如,我的单元格中带有 StyleValue1 的 detailTextLabel)要么不再存在,要么有时位于上方或下方的单元格中。 .这里是截图:第一个是正常状态,第二个是来自Version的detailTextLabel到上面的单元格,第三个是Measurement System detailTextLabel消失了......
这是我的代码:
- (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;
}
你知道我该如何解决这个问题吗?谢谢!