これはtableViewの私のコードです
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CounterCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CounterCell" owner:self options:nil];
cell = nibLoadedCell2;
}
Program *program = [memory getProgramAtIndex:[memory chosenProgram]];
NSMutableArray *arrayOfIntervals = [[NSMutableArray alloc] init];
arrayOfIntervals = program.arrayOfIntervals;
NSMutableDictionary *interval = [arrayOfIntervals objectAtIndex:indexPath.row];
UITextField *intervalName = (UITextField *)[cell viewWithTag:1];
intervalName.text = [interval objectForKey:@"nameOfInterval"];
[intervalName addTarget:self action:@selector(returnKey:) forControlEvents:UIControlEventEditingDidEndOnExit];
[intervalName addTarget:self action:@selector(editingEnded:) forControlEvents:UIControlEventEditingDidEnd];
[intervalName addTarget:self action:@selector(editTextField:) forControlEvents:UIControlEventEditingDidBegin];
timeInSeconds = [[interval objectForKey:@"timeInSeconds"] intValue];
if (indexPath.row == 0) {
firstCellGeneralTime = timeInSeconds;
}
NSString *time = [self timeTextWithTimeInSeconds:timeInSeconds];
UILabel *intervalTime = (UILabel *)[cell viewWithTag:2];
intervalTime.text = time;
if (indexPath.row == 0) {
majorLabel.text = time;
}
UILabel *hourString = (UILabel *)[cell viewWithTag:11];
hourString.text = [NSString stringWithFormat:@"%d",hoursInt];
UILabel *minuteString = (UILabel *)[cell viewWithTag:12];
minuteString.text = [NSString stringWithFormat:@"%d",minutesInt];
UILabel *secondString = (UILabel *)[cell viewWithTag:13];
secondString.text = [NSString stringWithFormat:@"%d",secondsInt];
UIButton *editTime = (UIButton *)[cell viewWithTag:21];
[editTime addTarget:self action:@selector(openPicker:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
私のテーブル ビューには 3 つ未満のセルが表示され、特定の時点で最初のセルを削除すると、4 番目のセルが表示されます。
問題は、異なるはずの 4 番目のセルが 3 番目のセルとまったく同じであることです。
必要に応じて再利用します。
何を間違えたのかわからない。
これは、セルを削除するためのコードです。
NSIndexPath *firstCellIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *arrayOfIndexPath = [[NSArray alloc] initWithObjects:firstCellIndexPath, nil];
[atableView deleteRowsAtIndexPaths:arrayOfIndexPath withRowAnimation:UITableViewRowAnimationTop];