不能更改自定义UITableViewCell中的透明BG(分组表视图)

有许多关于UITableViews(分组和普通)的单元格背景(自定义或标准)的问题,但是我没有发现这个特定的问题。

基本上我有一个分组风格的UITableView。

问题:我无法让我的自定义单元格具有透明背景以外的任何东西。

这是我的表格看起来像我实现我的自定义单元格之前(即这只是一个普通的分组表格视图):

在这里输入图像说明

标准,正常分组桌面。 大。 但是我想要自定义单元格。

所以我build立了一个如下所示的自定义单元格:

在这里输入图像说明

有了这个层次:

在这里输入图像说明

和这个单元格的背景元数据:

在这里输入图像说明

不幸的是,无论我做什么,无论是将背景变为白色,清晰还是黑色,都没有什么不同,我的桌面视图仍然是这样的:

在这里输入图像说明

(这是表视图的背景,fwiw,即现在这些单元格是透明的)。

而且,当然,我不能通过改变添加到单元格中的视图的背景来解决这个问题,因为那么所有的东西看起来就像这样(注意没有圆angular等等):

在这里输入图像说明

这显然是丑陋的,不可接受的。

如何使单元格具有像标准默认单元格一样的普通白色背景? 奇怪的是,上周我的一个应用程序做了一个自定义的单元格完全相同的程序,那些背景出来白色就好了。

我在这里错过了什么? 我所需要的是我的自定义单元格具有符合分组表格视图的弯曲顶部和底部angular落的白色背景。 我在其他实现中已经看到了白色的背景,所以我知道它可以用一个自定义的单元格。 但有些东西在这里不起作用!

我很高兴发布任何代码,只是不知道什么是需要/想要的。 这是我的cellForRowAtIndexPath方法(这只是tableView的核心数据版本:cellForRowAtIndexPath :):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForManagedObject:(NSManagedObject *)managedObject { static NSString *ReuseIdentifier = @"customSummaryCell"; CustomSummaryTableViewCell *cell = (CustomSummaryTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ReuseIdentifier]; if (cell == nil) { NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomSummaryTableViewCell" owner:nil options:nil]; for (id currentObject in nibObjects) { if([currentObject isKindOfClass:[CustomSummaryTableViewCell class]]) { cell = (CustomSummaryTableViewCell *)currentObject; } } } cell.leftLabel.text = @"Some data"; cell.rightLabel.text = @"Some Info"; return cell; } 

我的课堂档案应该基本不变,但在这里他们是。 我的自定义单元类的.h文件:

import

 @interface CustomSummaryTableViewCell : UITableViewCell { IBOutlet UIView *backgroundView; IBOutlet UILabel *leftLabel; IBOutlet UILabel *rightLabel; } @property (nonatomic, retain) IBOutlet UIView *backgroundView; @property (nonatomic, retain) IBOutlet UILabel *leftLabel; @property (nonatomic, retain) IBOutlet UILabel *rightLabel; @end 

和.m文件:

导入“CustomSummaryTableViewCell.h”

 @implementation CustomSummaryTableViewCell @synthesize backgroundView; @synthesize leftLabel; @synthesize rightLabel; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)dealloc { [leftLabel release]; [rightLabel release]; [backgroundView release]; [super dealloc]; } @end 

请注意,我已将 xib中单元格的类更改为CustomSummaryTableViewCell

任何帮助将不胜感激在这里,不知道是什么问题,这是让我坚果!

提前致谢。

我发现将子视图添加到单元格比实现自定义单元格更容易。 在你的情况下,在一个单元中有两个标签,看起来很容易。

编辑 – 简单的例子

 -(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath { . . . UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labelWidth, labelHeight)]; [label2 setText:@"Something"]; [[cell contentView] addSubview:label2]; return cell; } 

编辑 – 这是一个真实的,完整的例子:

 -(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath { static NSString *reusableCell = @"reusableCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusableCell]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableCell] autorelease]; thumbnail = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 106, 81)]; feedTitle = [[UILabel alloc] initWithFrame:CGRectMake(116, 3, [IOSDevice screenWidth] - 140, 25)]; postDate = [[UILabel alloc] initWithFrame:CGRectMake(116, 10, [IOSDevice screenWidth] - 140, 50)]; description = [[UILabel alloc] initWithFrame:CGRectMake(116, 45, [IOSDevice screenWidth] - 140, 50)]; // setting tag reminders so we can identify the element to replace [thumbnail setTag:1]; [feedTitle setTag:2]; [postDate setTag:3]; [description setTag:4]; [[cell contentView] addSubview:thumbnail]; [[cell contentView] addSubview:feedTitle]; [[cell contentView] addSubview:description]; [[cell contentView] addSubview:postDate]; [thumbnail release]; [feedTitle release]; [description release]; [postDate release]; } thumbnail = (UIImageView *)[[cell contentView] viewWithTag:1]; feedTitle = (UILabel *)[[cell contentView] viewWithTag:2]; postDate = (UILabel *)[[cell contentView] viewWithTag:3]; description = (UILabel *)[[cell contentView] viewWithTag:4]; [feedTitle setBackgroundColor:[UIColor clearColor]]; [feedTitle setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16]]; [feedTitle setTextColor:[UIColor colorWithRed:0.215 green:0.215 blue:0.215 alpha:1.0]]; [description setBackgroundColor:[UIColor clearColor]]; [description setFont:[UIFont fontWithName:@"Helvetica" size:12]]; [description setTextColor:[UIColor colorWithRed:0.328 green:0.328 blue:0.328 alpha:1.0]]; [description setNumberOfLines:2]; [description setLineBreakMode:UILineBreakModeWordWrap]; [postDate setBackgroundColor:[UIColor clearColor]]; [postDate setFont:[UIFont fontWithName:@"Helvetica" size:12]]; [postDate setTextColor:[UIColor colorWithRed:0.707 green:0.180 blue:0.141 alpha:1.0]]; [thumbnail setImage:[[items objectAtIndex:[indexPath row]] objectForKey:@"thumb"]]; [feedTitle setText:[[items objectAtIndex:[indexPath row]] objectForKey:@"title"]]; [description setText:[[items objectAtIndex:[indexPath row]] objectForKey:@"summary"]]; // Format date NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterLongStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; [postDate setText:[dateFormatter stringFromDate:[[items objectAtIndex:[indexPath row]] objectForKey:@"date"]]]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; if([feedList contentOffset].y < -50) { shouldUpdate = TRUE; [activityIndicator stopAnimating]; [feedList setContentOffset:CGPointMake(0, -30) animated:NO]; [self loadData]; loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -25, [IOSDevice screenWidth], 20)]; [loadingLabel setText:@"Loading New Data"]; [loadingLabel setTextAlignment:UITextAlignmentCenter]; [loadingLabel setBackgroundColor:[UIColor clearColor]]; [loadingLabel setTextColor:[UIColor colorWithRed:0.215 green:0.215 blue:0.215 alpha:1.0]]; [loadingLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; reloadingSpinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(70, -25, 20, 20)]; [reloadingSpinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; [reloadingSpinner startAnimating]; [reloadingSpinner setHidesWhenStopped:YES]; [feedList addSubview:reloadingSpinner]; [feedList addSubview:loadingLabel]; } return cell; } 

在nib文件中检查UITableViewCell视图的Alpha和Background。

Alpha应该是1.0。