0

リソースフォルダに50枚の画像のフォルダ(「beeanim」と呼ばれる)があります。これらの画像で配列を埋めてから、画像でアニメーションを実行したいと思います。各画像にはbee1bee2.........という名前が付けられて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];


}
4

2 に答える 2

3
for(int i = 1; i <= 51; i++)

iの最後の値は51になります。そのような画像は、あなたの説明によれば存在しません。したがって、

[UIImage imageNamed:]に挿入できないnilを返しますNSMutableArray

于 2012-05-30T18:55:33.660 に答える
0

画像がすでにアプリにバンドルされている場合は、フォルダー名は必要ありません。試してみてください:

for(int i = 1; i <= 51; i++) {
    fileName = [NSString stringWithFormat:@"bee%d.png", i];
    [imageArray addObject:[UIImage imageNamed:fileName]];
}
于 2012-05-30T18:51:22.370 に答える