有许多关于 UITableViews(分组和普通)中单元格(自定义或标准)背景的各种问题的帖子,但我找不到这个具体问题的提及。
基本上我有一个分组样式的 UITableView。
问题:我无法让我的自定义单元格具有透明背景以外的任何内容。
这是我实现自定义单元格之前的表格视图(即这只是一个普通的分组表格视图):
标准的、正常的分组表格视图。伟大的。但我想要自定义单元格。
所以我构建了一个如下所示的自定义单元格:
使用此层次结构:
这个单元格的背景元数据:
不幸的是,无论我做什么,无论是将背景更改为白色、透明还是黑色,都没有任何区别,我的表格视图仍然看起来像这样:
(这是表格视图背景,fwiw。即这些单元格现在是透明的)。
而且,当然,我不能通过改变我添加到单元格的视图的背景来解决这个问题,因为那样一切都看起来像这样(注意没有圆角等):
这显然是丑陋和不可接受的。
如何让单元格像标准默认单元格一样具有正常的白色背景?奇怪的是,对于上周的一个应用程序,我按照完全相同的程序制作了一个自定义单元格,并且这些背景呈现为白色就好了。
我在这里错过了什么?我所需要的只是让我的自定义单元格具有符合分组表视图的弯曲顶角和底角的白色背景。我在其他实现中看到了白色背景,所以我知道使用自定义单元格是可能的。但是有些东西在这里不起作用!
我很高兴发布任何代码,只是不确定需要/想要什么。这是我的 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 文件:
进口
@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
任何帮助将不胜感激,不知道问题是什么,这让我发疯了!
提前致谢。