テーブルビューに 9 行あり、ボタンを行 1 と 2 だけに追加したいと考えています。コードを初めて実行すると、1 と 2 にボタンが表示されます。しかし、テーブルビューをスクロールすると、行 4,5 がランダムに表示され始めます。 、8、9。コードは以下です。私が間違っていることをアドバイスしてください。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"Row %d",[indexPath row]];
if([indexPath row] == 0 || [indexPath row] == 1)
{
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
return cell;
}