このはSHOULDをシンプルにしてください。代わりに、それは最後の1時間ほど、私からの地獄を混同しています。私が何をしていても、この変数は値の変更を拒否します
ヘッダファイル:
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を渡すとnilが返される可能性があります。 – jbat100
@madmw私はそのクラスの基礎を投稿しました。最下部の編集をご覧ください。 –