私は非常に基本的なことをしようとしています。UIViewサブクラスにサブビューを追加したいと思います。これを以下のようにinitWithFrameメソッドに入れると思いますが、このクラスのインスタンスであるビューはこのサブビューを描画しません。私は何が間違っているのですか?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
redView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
[redView setBackgroundColor:[UIColor redColor]];
[self addSubview:redView];
}
return self;
}
ところで、redViewは、次のように、サブクラスのヘッダーで定義されたプロパティです。
@property (strong, nonatomic) UIView *redView;
読んでくれてありがとう!