2

セルの 2 つの完全に異なる外観 (およびコンテンツ) をセットアップしたいと考えています。(1 つは選択され、もう 1 つは選択されていません)。

このコードは機能しますが、選択したセルの画像が 50% 透明であるため、下部に BackgroundView が表示されます。

明確に言うと、selectedBackgroundView は、選択されたときにのみ表示される要素をセルに入力する優れた方法を提供します。セルに入力する BackgroundView 以外の場所はありますか? selectedBackgroundView に表示されない場所

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSString *cellIdentifier = @"hello";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
  }


    UIImage *image = [UIImage imageNamed:@"listview_btn.png"];
    UIImage *imageThumb = [UIImage imageNamed:@"01_thumb.jpg"];
    UIImageView* imageView = [[UIImageView alloc] initWithImage:imageThumb];
    [imageView setFrame:CGRectMake(0, 0, 50, 67)];
    [cell setBackgroundView:[[UIImageView alloc]initWithImage:image] ];
    [cell.backgroundView addSubview:imageView];



    UIImage *imageSel = [UIImage imageNamed:@"listview_btn_on.png"];
    UIImage *imageThumbSel = [UIImage imageNamed:@"01_thumb_Sel.jpg"];
    UIImageView* imageViewSel = [[UIImageView alloc] initWithImage:imageThumbSel];
    [imageViewSel setFrame:CGRectMake(110, 0, 50, 67)];
    [cell setSelectedBackgroundView:[[UIImageView alloc]initWithImage:imageSel] ];
    [cell.selectedBackgroundView addSubview:imageViewSel];
4

1 に答える 1

0

選択した背景ビューを不透明にします。常に背景ビューの上に挿入されるため、Photoshopまたは別のグラフィックエディタでそれらを合成して、選択した背景ビューとして結果を使用できます。

このアプローチを使用する余裕がない場合(私はまだ強くお勧めします)、両方をサブクラス化UITableViewCellしてオーバーライドし、選択/ハイライト表示時に背景ビュープロパティをnilに設定し、選択解除/ハイライト解除時に復元することができます。しかし、それははるかに複雑なアプローチです、IMHO。setHighlighted:animatedsetSelected:animated

于 2012-04-28T05:00:39.840 に答える