カスタムスライダーのあるビューがあります。UITableViewCell のインスタンスを生成する TableViewController のサブクラスを使用しています。各 tableViewCell 内に、カスタム スライダー (UI ビュー) をサブビューとして追加します。ここには、スライダーのコントロール ノブとして機能するビューがあります。これは、ジェスチャー認識機能を備えた UIView の単なるサブクラスです。コントロール ノブ クラスの drawRect メソッドは、UIImage を受け取り、drawAtPoint を実行します。これはうまくいきます!要約すると、次のようになります。
UITableView -> UITableViewCell -> UITableViewCell.contentView -> SliderView -> SliderKnob -> UIImage
この問題は、テーブル ビューからテーブル セルをスクロールするときに発生します。ノブの UIImage は保持されます。セルがキューから取り出されるたびに、残りの画像の複製を取得することになります。いくつかの NSLog ステートメントをセットアップし、各サブビューで drawRect が呼び出されることを確認しました。セルのレンダリングを更新するために必要なことはありますか? UITableViewCell のサブビューで setNeedsDisplay を使用しようとしましたが、UIImage の複製を防ぐことができませんでした。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SliderView";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
SliderView *slider = [[[SliderView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 130)] autorelease];
// Configure the data for the cell.
NSDictionary *dataItem = [data objectAtIndex:indexPath.row];
slider.dimensionName = [dataItem objectForKey:@"Name"];
slider.upperExtreme = [dataItem objectForKey:@"Upper Extreme"];
slider.lowerExtreme = [dataItem objectForKey:@"Lower Extreme"];
slider.score = [[dataItem objectForKey:@"Score"] intValue];
cell.selectionStyle = UITableViewCellEditingStyleNone;
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"track_grainy.png"]];
[cell.contentView addSubview:slider];
return cell;
}