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.
精彩评论