コメントで述べたように、ボリューム コントロールのあるセルは非ボリューム セルに再利用される可能性があるため、既に存在する場合は削除する必要があります。これを行う方法の例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
//remove the volume control (which we tagged as 10) if it already exists...
UIView *v = [cell.contentView viewWithTag:10];
[v removeFromSuperview];
cell.textLabel.text = @"some text";
if (indexPath.section == 7)
{
if (indexPath.row == 1)
{
cell.detailTextLabel.text = @"";
MPVolumeView *systemVolumeSlider = [[MPVolumeView alloc] initWithFrame:CGRectMake(100, 10, 200, 100)];
//set a tag so we can easily find it (to remove it)...
systemVolumeSlider.tag = 10;
[cell.contentView addSubview:systemVolumeSlider];
[systemVolumeSlider release];
return cell;
}
}
cell.detailTextLabel.text = @"detail";
return cell;
}
あなたのコメントでは、ボリューム コントロールは 8 番目のセクションの 2 行目にのみある必要があるように思われるため、例はそのように記述されています。必要に応じて変更します。