私はこれらの2つのコードを持っています。最初のものは完全に機能します:
UIView *tmp = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 60.0f, 296.0f, 44.0f)];
[self.dynamicView addSubview:tmp];
[tmp release];
2つ目はほとんど同じですが、ビューが表示されません。
CommentBox *commentBox = [[CommentBox alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 296.0f, 44.0f)];
[self.dynamicView addSubview:commentBox];
[commentBox release]; // Why does this remove the view?
ビューを削除すると[commentBox release]
、驚くほどビューが表示されます。しかし、これら2つのコードスニペットに違いは見られません。
CommentBoxの初期化は次のようになります。
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Load the nib:
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"CommentBox" owner:self options:nil];
self = [nibObjects objectAtIndex:0];
}
return self;
}