removeFromSuperview由于某种原因用UIImageView替换对象?

时间:2011-05-24 00:07:10

标签: iphone objective-c

我已经浏览了我的代码中分配的每一件事,并给它一个-1的标签,除了图标,它们用完了标签系统。所以这是我的代码:

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将对象返回为图标。 NSLog 2将对象返回到UIImageView,尽管我为每个UIImageView彻底搜索我的代码并给它一个-1标签。通过移动NSLog 2,我发现行[icon removeFromSuperview];就是问题所在。如果不包括该行,则不会发生。但显然我需要从superview中删除它,而.alpha = 0太多的补丁修复。

1 个答案:

答案 0 :(得分:1)

您对标签使用了什么价值?有时候如果我使用的值太低我会遇到麻烦(我假设因为UIKit正在使用该标记值)。

尝试将index设置为一些随机的大号。

另外,为什么不使用实例变量来引用Icon?然后你就不必乱用它的标签识别图标了。

相关问题