1
在我的iPhone應用程序的我viewDidLoad方法中,我有以下代碼:改變一個UIImageView的動畫圖像
zombie[i].animationImages = zombieImages;
zombie[i].animationDuration = 0.8/zombieSpeed[i];
zombie[i].animationRepeatCount = -1;
[zombie[i] startAnimating];
後來在應用程序下面的代碼被稱爲:
[zombie[i] stopAnimating];
zombie[i] = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zh.png"]];
zombie[i].animationImages = flyingZombieImages;
zombie[i].animationDuration = 0.8/zombieSpeed[i];
zombie[i].animationRepeatCount = -1;
[zombie[i] startAnimating];
這導致應用程序崩潰,並在線上使用EXC_BAD_ACCESS zombie[i].animationImages = flyingZombieImages;
flyingZombieImages
使用以下代碼進行初始化:(zombieImages
以相同方式初始化)
NSMutableArray *flyingZombieImages = [NSMutableArray array];
for (NSUInteger i=1; i <= 29; i++) {
NSString *imageName = [NSString stringWithFormat:@"flzom%d.png", i];
[flyingZombieImages addObject:[UIImage imageNamed:imageName]];
}
爲什麼會發生這種情況?有沒有解決方法?
哪一行崩潰? –
zombie [i] .animationImages = flyingZombieImages; –
flyingZombieImages如何初始化?似乎是這是什麼原因造成的問題。你有沒有調試過,看看數組是否真的有效? – Dima