我正在开发一个幻灯片应用程序。它应该淡入和淡出数组中的图像。不知何故,它在 ios 模拟器中完美运行,但在实际设备上崩溃并出现以下错误:
"slideshow[4452:907] * 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *第一次抛出调用堆栈:(0x31be52a3 0x39a7097f 0x31b2f8d9 0x97e21 0x33a0c595 0x343aedcda7 0x33a8a1e9 0x97b5f 0x33a4dad9 0x33a4d663 0x33a4584b 0x339edc39 0x339ed6cd 0x339ed11b 0x356df5a3 0x356df1d3 0x31bba173 0x31bba117 0x31bb8f99 0x31b2bebd 0x31b2bd49 0x33a44485 0x33a41301 0x97853 0x39ea7b20) libc++abi.dylib: terminate called throwing an exception (lldb) "
我附上了我的代码(我不明白出了什么问题)。有人可以帮忙吗?
实现文件:
//View Controller.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
backgroundImageQueue = [[NSMutableArray alloc] init];
[backgroundImageQueue addObject:
[UIImage imageNamed:@"DSCN7419.jpg"]];
[backgroundImageQueue addObject:
[UIImage imageNamed:@"DSCN7422.jpg"]];
[backgroundImageQueue addObject:
[UIImage imageNamed:@"DSCN7238.jpg"]];
/* Add any more images to the queue */
backgroundB.image = [backgroundImageQueue
objectAtIndex:[backgroundImageQueue count] - 1];
[backgroundImageQueue insertObject:
backgroundB.image atIndex:0];
[backgroundImageQueue removeLastObject];
backgroundA.alpha = 1.0;
backgroundB.alpha = 0.0;
[self nextAnimation];
}
-(void)nextAnimation {
backgroundA.image = backgroundB.image;
backgroundB.image = [backgroundImageQueue
objectAtIndex:[backgroundImageQueue count] - 1];
[backgroundImageQueue insertObject:
backgroundB.image atIndex:0];
[backgroundImageQueue removeLastObject];
backgroundA.alpha = 1.0;
backgroundB.alpha = 0.0;
[UIView beginAnimations:@"fade" context:NULL];
[UIView setAnimationDuration:6];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:
@selector(nextAnimation)];
backgroundA.alpha = 0.0;
backgroundB.alpha = 1.0;
[UIView commitAnimations];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
头文件:
//View Controller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
IBOutlet UIImageView *backgroundA;
IBOutlet UIImageView *backgroundB;
NSMutableArray *backgroundImageQueue;
}
@end