[英]My iPhone app crashes after returning from background. Cause: UIImage problem
First off, I want to say this site is AWESOME! 首先,我想说这个网站真棒! and it helped me do lots of stuff while creating my iPhone app. 它帮助我在创建iPhone应用程序时做了很多事情。
Now, my problem is: 现在,我的问题是:
When I launch my app, I have a UIImageView that loads an image depending on an if/else statements in 启动应用程序时,我有一个UIImageView,它根据其中的if / else语句加载图像
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
method. 方法。 These images are assigned as follows: 这些图像分配如下:
BG.image = someImage;
of course, BG is the UIImageView, and someImage is an iVar with @property, @synthesis. 当然,BG是UIImageView,someImage是具有@ property,@ synthesis的iVar。 someImage is initialized with an image from the main bundle in viewDidLoad: 使用viewDidLoad中主包中的图像初始化someImage:
- (void)viewDidLoad {
//init stuff from file
someImage = [UIImage imageNamed:@"FirstViewBG_5N.png"];
[super viewDidLoad];}
My app runs happily, loading images according to touchBegan (as mentioned), BUT! 我的应用程序运行愉快,根据touchBegan(如上所述)加载图像,但是!
When my app is sent to background and comes back, it crashes upon first touch. 当我的应用发送到后台并返回时,它在第一次触摸时崩溃。
When I replaced: 当我更换时:
BG.image = someImage
with: 与:
BG.image = [UIImage imageNamed:@"FirstViewBG_5N.png"];
it runs happily?! 它运行愉快吗? I think the someImage is flushed or corrupts? 我认为someImage已刷新或损坏?
I don't want to leave it like this because imageNamed method reads from disk every time, which will cause performance problems, i think? 我不想这样保留它,因为imageNamed方法每次都从磁盘读取数据,这会导致性能问题,我认为呢?
I think my question is clear? 我想我的问题很清楚吗? It is that: 就是它:
1- Why will my app crash after returning from backgroud 2- How do I solve this? 1-为什么我的应用程序从backgroud返回后会崩溃2-如何解决此问题?
All your help is appreciated! 感谢您的帮助! Thanks! 谢谢!
'someImage' got released. “ someImage”被释放。 retain it 保留它
ps be careful to release it on dealloc ;). ps小心释放dealloc;)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.