我正在製作幻燈片應用程序。它應該淡入淡出數組中的圖像。不知怎的,它完美的iPhone模擬器,但崩潰,並顯示以下錯誤在實際設備上:幻燈片應用程序崩潰
「幻燈片[4452:907] *終止應用程序由於未捕獲的異常‘NSInvalidArgumentException’,原因是:「* - [__ NSArrayM insertObject:atIndex:]:對象不能是零」 *第一擲調用堆棧: (0x31be52a3 0x39a7097f 0x31b2f8d9 0x97e21 0x33a0c595 0x33a4cd79 0x33a48aed 0x33a8a1e9 0x97b5f 0x33a4dad9 0x33a4d663 0x33a4584b 0x339edc39 0x339ed6cd 0x339ed11b 0x356df5a3 0x356df1d3 0x31bba173 0x31bba117 0x31bb8f99 0x31b2bebd 0x31b2bd49 0x33a44485 0x33a41301 0x97853 0x39ea7b20) libC++ abi.dylib:終止調用拋出異常 (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
任何機會是文件名DSCN7419.JPG而不是DSCN7419.jpg? – borrrden
是的,文件名是DSCN7419.JPG。 – user2563039
那就有你的答案(參見馬塞洛的回答) – borrrden