4 つのセクションを持つ基本的な UITableView があります。Switch ステートメントを使用して、各セクションのコンテンツを制御します。
最初の 3 つのセクションの行に表示されるボタンをプログラムで作成しますが、4 番目のセクションには表示されません。ただし、ボタンは 4 番目のセクションの行にランダムに表示されます。
これは、セルが再利用されているためだと思いますが、Switch ステートメントで各セクションの行を作成すると、これがどのように発生するのかわかりません。どんなアイデアでも大歓迎です。
私は次のように構成されたカスタムセルを使用しています:`
static NSString *CustomCellIdentifier = @"DashboardCell";
DashboardCell *cell = (DashboardCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DashboardCell"
owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[DashboardCell class]])
cell = (DashboardCell *)oneObject;
}
// Configure the cell.`
このボタンを作成するコードは次のとおりです。
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(200, 11, 50, 50);
UIImage *iConnect = [UIImage imageNamed:@"connect.png"];
[button setImage:iConnect forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];`