从后台返回后,我的iPhone应用程序崩溃了。原因:UIImage问题 [英] My iPhone app crashes after returning from background. Cause: UIImage problem

查看:113
本文介绍了从后台返回后,我的iPhone应用程序崩溃了。原因:UIImage问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说这个网站太棒了!它帮助我在创建我的iPhone应用程序时做了很多事情。

First off, I want to say this site is AWESOME! and it helped me do lots of stuff while creating my iPhone app.

现在,我的问题是:

当我启动我的应用程序时,我有一个UIImageView根据if / else语句加载图像

When I launch my app, I have a UIImageView that loads an image depending on an if/else statements in

- (void)touchesBegan :( NSSet *)触及withEvent:(UIEvent *)事件

方法。这些图像分配如下:

method. These images are assigned as follows:

BG.image = someImage;

当然,BG是UIImageView,someImage是带有@property的iVar,@ synthesis。 someImage使用viewDidLoad中主包的图像进行初始化:

of course, BG is the UIImageView, and someImage is an iVar with @property, @synthesis. someImage is initialized with an image from the main bundle in viewDidLoad:

- (void)viewDidLoad {

//init stuff from file
someImage = [UIImage imageNamed:@"FirstViewBG_5N.png"];

[super viewDidLoad];}

我的应用程序运行愉快,加载图像根据touchBegan(如上所述),但是!

My app runs happily, loading images according to touchBegan (as mentioned), BUT!

当我的应用程序被发送到后台并返回时,它会在第一次触摸时崩溃。

When my app is sent to background and comes back, it crashes upon first touch.

当我更换时:

BG.image = someImage

with:

BG.image = [UIImage imageNamed:@"FirstViewBG_5N.png"];

它运行愉快吗?!我认为someImage被刷新或腐败?

it runs happily?! I think the someImage is flushed or corrupts?

我不想这样离开,因为imageNamed方法每次都从磁盘读取,这会导致性能问题,我想想?

I don't want to leave it like this because imageNamed method reads from disk every time, which will cause performance problems, i think?

我认为我的问题很明确?就是这样:

I think my question is clear? It is that:

1-为什么我的应用程序会在从backgroud返回后崩溃
2-如何解决这个问题?

1- Why will my app crash after returning from backgroud 2- How do I solve this?

感谢您的所有帮助!
谢谢!

All your help is appreciated! Thanks!

推荐答案

我猜这次崩溃是EXC_BAD_ACCESS(但我猜是因为你没有发布那个信息)。

I'm guessing the crash is EXC_BAD_ACCESS (but am guessing because you didn't post that information).

如果someImage是一个实例变量,你应该合成它并使用它的访问器(self.someImage),以便保留或复制它。就目前而言,你正在为someImage分配一些内容,但是当你稍后尝试访问它时它已经消失了。

If "someImage" is an instance variable, you should synthesize it and use its accessor (self.someImage) so it is retained or copied. As it stands, you're assigning something to someImage but it's gone by the time you're trying to access it later.

这篇关于从后台返回后,我的iPhone应用程序崩溃了。原因:UIImage问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆