这个SHOULD是简单的。相反,在最后一个小时左右,我感到困惑。无论我做什么,这个变量拒绝改变值
头文件:
CellBackgroundView距离的UIView衍生的自定义类。
@interface CustomCell : UITableViewCell {
CellBackgroundView *customBackgroundView;
}
@property (strong) CellBackgroundView *customBackgroundView;
预期不起作用
代码:
所有我想要做的就是分配东西customBackgroundView。
customBackgroundView = [[CellBackgroundView alloc] initWithFrame:CGRectZero];
[self addSubview:customBackgroundView];
-
什么也没有发生。在调试器中,我可以看到customBackgroundView是0x0。以下也不起作用,虽然“背景”确实分配了一个内存位置。 customBackgroundView仍然是0x0。
CellBackgroundView *background = [[CellBackgroundView alloc] initWithFrame:CGRectZero];
customBackgroundView = background.
[self addSubview:customBackgroundView];
发生了什么事?为什么这不起作用? 我打开了ARC。
EDITS:
CellBackgroundView的基础是:
- (BOOL) isOpaque {
return NO;
}
-(void)drawRect:(CGRect)aRect {
//Custom drawing code
}
而且,上面的代码,当我用的UITableViewCell的官方 'backgroundView' 属性的罚款。
任何东西CellBackgroundView执行有关?像一个自定义的initWithFrame? – djromero
你可以发布'CellBackgroundView'的'initWithFrame:'方法吗?它可能是通过它CGRectZero返回零。 – jbat100
@madmw我已经发布了该类的基础 - 请参阅底部的编辑。 –