Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch UITableView单元格:选择backgroundView而不显示backgroundView_Cocoa Touch_Ipad_Uitableview - Fatal编程技术网

Cocoa touch UITableView单元格:选择backgroundView而不显示backgroundView

Cocoa touch UITableView单元格:选择backgroundView而不显示backgroundView,cocoa-touch,ipad,uitableview,Cocoa Touch,Ipad,Uitableview,我想设置一个单元格的两个完全不同的外观(和内容)。(一个选中,一个未选中) 这段代码可以工作,但是,因为所选单元格的图像是50%透明的,所以我可以看到底部的背景视图 在clear中,selectedBackgroundView提供了一种很好的方法,可以使用仅在选中时可见的元素填充单元格。是否有BackgroundView以外的其他位置来填充单元格,该位置如何不会显示在selectedBackgroundView上 - (UITableViewCell *)tableView:(UITableVi

我想设置一个单元格的两个完全不同的外观(和内容)。(一个选中,一个未选中)

这段代码可以工作,但是,因为所选单元格的图像是50%透明的,所以我可以看到底部的背景视图

在clear中,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];

使选定的背景视图不透明。由于它始终插入背景视图上方,因此可以在Photoshop或其他图形编辑器中合成它们,并将结果用作选定的背景视图


如果您负担不起这种方法(我仍然强烈推荐),您可以将
UITableViewCell
子类化,并覆盖
setHighlighted:animated
setSelected:animated
以在选中/高亮显示时将背景视图属性设置为零,在取消选中/取消高亮显示时将其恢复。然而,这是一种更复杂的方法,IMHO。

使选定的背景视图不透明。由于它始终插入背景视图上方,因此可以在Photoshop或其他图形编辑器中合成它们,并将结果用作选定的背景视图


如果您负担不起这种方法(我仍然强烈推荐),您可以将
UITableViewCell
子类化,并覆盖
setHighlighted:animated
setSelected:animated
以在选中/高亮显示时将背景视图属性设置为零,在取消选中/取消高亮显示时将其恢复。然而,这是一种更复杂的方法,IMHO。

我只需单击一下就可以修复代码格式。也许你应该这样做,下次点击。要执行此操作,请选择问题中插入的所有代码,然后按
{}
按钮。它将添加适当的降价缩进,这样您的代码是可读的,并获得了良好的配色方案:-),当然它不是xCode。Xcode不是iPhone。Xcode只是一个IDE,它是一个编写代码的工具。如果您的问题与IDE本身无关(例如,“如何在Xcode中打开行号?”,请不要使用标签。此问题没有答案?(感谢Matthias的更正)我只需单击一下就可以修复代码格式。也许你应该在下次单击时执行此操作。要执行此操作,请选择插入到问题中的所有代码,然后按
{}
按钮。它将添加适当的标记缩进,以便您的代码可读并获得良好的配色方案:-),当然它不是xCode。Xcode不是iPhone。Xcode只是一个IDE,它是一个编写代码的工具。如果您的问题与IDE本身无关(例如,“如何在Xcode中打开行号?”,请不要使用标签。此问题没有答案?(感谢Matthias的更正)