J'ai ces deux morceaux de code. Le premier fonctionne parfaitement:iPhone: [subview release] supprime ma sous-vue de l'affichage
UIView *tmp = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 60.0f, 296.0f, 44.0f)];
[self.dynamicView addSubview:tmp];
[tmp release];
Le second est à peu près le même, mais la vue n'apparaît pas.
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?
Si je supprime la [commentBox release]
la vue apparaît étonnamment. Mais je ne vois pas de différence entre ces deux extraits de code.
init pour le CommentBox ressemble à ceci:
- (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;
}
Merci Graham. J'ai posté ma nouvelle solution ci-dessous. – znq