這個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我已經發布了該類的基礎 - 請參閱底部的編輯。 –