【发布时间】:2012-09-02 15:01:57
【问题描述】:
我在 IB 中设置了 UITableView 的分隔线样式和颜色,但是,当表格加载时分隔线不可见。
我正在使用具有自定义超类CustomTableView 的 UITableView - 这是UITableView 的子类。在这张表中,我也使用了自定义的UITableViewCell。
我能想到的唯一问题是,如果我没有在我的 awakeFromNib 方法中调用“超级”实现 - 但我这样做是不可能的。
有什么想法吗?
用代码编辑
我的表格单元格如下 - CustomDefaultCell.h > CustomPlainCell.h > UITableViewCell
CustomDefaultCell.m
- (void)awakeFromNib
{
[super awakeFromNib];
// Called when loaded from a nib.
// Override all default cell behaviour here.
//
}
CustomPlainCell.m
- (void)awakeFromNib
{
[super awakeFromNib];
// Called when loaded from a nib.
// Override all default cell behaviour here.
//
// Normal background view
self.backgroundView = [[UIView alloc] initWithFrame:self.frame];
self.backgroundView.backgroundColor = [UIColor whiteColor];
// Selected background view
self.selectedBackgroundView = [[UIView alloc] init];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
//
// Background gradient
CAGradientLayer *selectedViewGradientLayer = [CAGradientLayer layer];
selectedViewGradientLayer.frame = CGRectMake(1.0f, 0.0f, 320.0f, CGRectGetHeight(self.frame) + 1.0f);
selectedViewGradientLayer.colors = @[(id)[UIColor colorWithHue:0.0f saturation:0.0f brightness:0.57f alpha:1.0f].CGColor, (id)[UIColor grayColor].CGColor];
[self.selectedBackgroundView.layer addSublayer:selectedViewGradientLayer];
}
【问题讨论】:
-
您是否使用 Quartz 来绘制您的内容?
-
我有一个 .xib 文件,对应的 .h 和 .m
-
我知道,但是 .h 和 m. 中有什么? (不要告诉我“里面有代码”!)
-
对不起,刚刚意识到这是一个多么愚蠢的答案:P 用代码编辑
-
哦,是的,就像我想的那样!您正在使用 Quartz 来绘制单元格的内容。解决方法:将所有setSelected方法的代码移到drawRect:.