开发者

How to avoid "message superview sent to freed object" iphone

I have this code:

 CardView *aCardView = [self prendiCartaDalMazzo];

 [aCardView removeFromSuperview]; 
 [self.mieCarte addSubview:aCardView];

when i try to add aCardView as as subview of mieCarte then i 开发者_C百科get this error:

objc[4800]: FREED(id): message superview sent to freed object=0x393f130 Program received signal: “EXC_BAD_INSTRUCTION”.

Thanks at all can help.


-removeFromSuperview does a release, which probably causes destruction (the superview's reference is probably the last remaining one)..

Do

[aCardView retain];
[aCardView removeFromSuperview];

...

instead.


removeFromSuperview also releases the receiver (just as addSubview: retains it).

You need to retain the card view before removing it and then release it again after adding it as a subview to another view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜