Reputation: 16051
I have been through every single thing allocated in my code and given it a tag of -1, except from the Icons, which use up the tag system. So here's my code:
NSLog(@" 1: %@", (Icon *)[self viewWithTag:index]);
Icon *icon = (Icon *)[self viewWithTag:index];
CGRect frame = icon.frame;
[icon removeFromSuperview];
icon = nil;
Icon *icon2 = [[Icon alloc] init];
[icon2 makeIconStandardWithTag:(int)index];
icon2.frame = frame;
[self addSubview:icon2];
NSLog(@" 2: %@", (Icon *)[self viewWithTag:index]);
NSLog 1 returns the object to be an icon. NSLog 2 returns the object to be a UIImageView, despite me searching my code thoroughly for every UIImageView and giving it a -1 tag. Through moving NSLog 2 around, i've discovered that the line [icon removeFromSuperview];
is the problem here. If that line isn't included, it doesn't happen. But obviously i need to remove it from superview and .alpha = 0
is too much of a patch-over fix.
Upvotes: 0
Views: 181
Reputation: 5999
What value are you using for the tag? Sometimes I have troubles if I use a value that's too low (I assume because UIKit
is using that tag value).
Try setting index
to some random large number.
Also, why not just use an instance variable to refer to the Icon? Then you won't have to mess around with identifying the icon by its tag.
Upvotes: 1