リソースフォルダに50枚の画像のフォルダ(「beeanim」と呼ばれる)があります。これらの画像で配列を埋めてから、画像でアニメーションを実行したいと思います。各画像にはbee1
、bee2
.........という名前が付けられてbee50
います。
xcodeでアプリを実行しようとすると、コンソールに次のようなエラーが表示されます。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
これにより、ファイル名を正しく参照していない可能性があると思いますが、他に方法がわかりません。助けていただければ幸いです。これは私のコードです:
-(void) createBeeImage {
NSString *fileName;
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
for(int i = 1; i <= 51; i++) {
fileName = [NSString stringWithFormat:@"beeanim/bee%d.png", i];
[imageArray addObject:[UIImage imageNamed:fileName]];
}
UIImageView * imgView = [[UIImageView alloc] initWithFrame:
CGRectMake(215, 250, 174, 80)];
imgView.animationImages = imageArray;
imgView.animationDuration = 2;
imgView.animationRepeatCount = 0;
imgView.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:imgView];
[imgView startAnimating];
}