tags:

views:

253

answers:

2

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 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.

+1  A: 

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

Do

[aCardView retain];
[aCardView removeFromSuperview];

...

instead.

Jim
That was the problem, thanks a lot.
Giovanni
i thougth that having a pointer to an instance of aCardView that was enalf thanks again
Giovanni
A: 

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.

Jasarien
Thanks for your clear answare.
Giovanni