开发者

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

开发者 https://www.devze.com 2022-12-23 16:19 出处:网络
I have this code: CardView *aCardView = [self prendiCartaDalMazzo]; [aCardView removeFromSuperview];

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

精彩评论

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