【发布时间】:2011-06-26 15:12:48
【问题描述】:
我有一个 UIImage* loadedPoofSprite,我像这样初始化它:
NSMutableDictionary* loadedDictionary=[NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",Main_Bundle_Path,poofConfigFileName]];
NSString *textureFileName = [[loadedDictionary objectForKey:@"metadata"] valueForKey:@"textureFileName"];
loadedPoofSprite = [UIImage imageNamed:textureFileName];
poofImage = [[UIImage imageNamed:textureFileName] CGImage];
从那里我使用我的 poofImage 并且一切似乎都很好,直到我的应用程序从后台恢复。我崩溃了,因为loadedPoofSprite 不见了。我认为避免这种情况的方法是像这样保留loadedPoofSprite:
[loadedPoofSprite autorelease];
loadedPoofSprite = [[UIImage imageNamed:textureFileName] retain];
这可行,但有人建议我这样做不是正确的方法,我基本上应该在 applicationWillEnterForeground 中再次加载loadedPoofSprite。我不明白为什么最好加载两次而不是保留它。处理上述问题的正确方法是什么?
谢谢!
【问题讨论】:
标签: ios background uiimage multitasking retain