我的应用程序在屏幕上随机移动 10 个 UIImageView,一旦 UIImageView 到达角落,它就会更改其图像。问题是:在应用程序之间切换并返回我的应用程序后,应用程序崩溃了。
控制台给了我这个消息:
"App" exited abnormally with signal 10: Bus error
崩溃日志指出:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000011
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
我认为问题是由于我正在使用的事实UIImage imageNamed
,这里是代码:
在ViewController.h中:
UIImage *red;
UIImage *green;
UIImage *blue;
UIImageView *ballOne;
UIImageView *ballTwo;
UIImageView *ballThree;
UIImageView *ballFour;
// And declare UIImageView for other balls
int clr
在ViewController.m中:
- (void)viewDidLoad {
...
red = [UIImage imageNamed: @"redTexture.png"];
green = [UIImage imageNamed: @"greenTexture.png"];
blue = [UIImage imageNamed: @"blueTexture.png"];
...
}
- (void)moveAll:(NSTimer *)theTimer{
...
// If UIImageView touches a corner, Do this:
clr = arc4random()%3 + 1;
switch (clr) {
case 1:
[ballOne setImage:red];
break;
case 2:
[ballOne setImage:green];
break;
case 3:
[ballOne setImage:blue];
break;
default:
break;
}
// And do this for the rest of 9 "balls"
}
为什么我的应用程序崩溃,我该如何解决?