我的 iPhone 应用程序从后台返回后崩溃。原因:UIImage问题
首先,我想说这个网站太棒了!它帮助我在创建 iPhone 应用程序时完成了很多事情。
现在,我的问题是:
中的 if/else 语句加载图像
当我启动我的应用程序时,我有一个 UIImageView,它根据-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event< /代码>
方法。这些图像的分配如下:
BG.image = someImage;
当然,BG是UIImageView,someImage是带有@property、@synthesis的iVar。 someImage 使用 viewDidLoad 中主包中的图像进行初始化:
- (void)viewDidLoad {
//init stuff from file
someImage = [UIImage imageNamed:@"FirstViewBG_5N.png"];
[super viewDidLoad];}
我的应用程序运行愉快,根据 touchBegan 加载图像(如上所述),但是!
当我的应用程序发送到后台并返回时,它会在第一次触摸时崩溃。
当我将: 替换
BG.image = someImage
为: 时,
BG.image = [UIImage imageNamed:@"FirstViewBG_5N.png"];
它运行得很愉快?!我认为 someImage 已被刷新或损坏?
我不想这样,因为 imageNamed 方法每次都会从磁盘读取,我认为这会导致性能问题?
我想我的问题很清楚了?就是这样:
1-为什么我的应用程序从后台返回后会崩溃 2-我该如何解决这个问题?
感谢您的所有帮助! 谢谢!
First off, I want to say this site is AWESOME! and it helped me do lots of stuff while creating my iPhone app.
Now, my problem is:
When I launch my app, I have a UIImageView that loads an image depending on an if/else statements in
-(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. 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];}
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.
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?
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- Why will my app crash after returning from backgroud
2- How do I solve this?
All your help is appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“someImage”已发布。保留它
'someImage' got released. retain it
ps 小心在 dealloc 上释放它;)。
p.s. be careful to release it on dealloc ;).