私は Obj-C の初心者です。私はこれをもっとよく学ぶ必要があるので、私が間違っていることを教えてください..
私は画像の配列を持っています....実行のさまざまな時点で、最後の要素を前の画像の1つに置き換える必要があります...したがって、最後の画像は常に前の画像の1つを複製します。置換を行うと、例外がスローされます! setCorrectImage への呼び出しを削除すると、機能します。
ここ数時間、これを理解することができません:-(
controller.h の宣言は次のとおりです。
NSMutableArray *imageSet;
UIImage *img, *img1, *img2, *img3, *img4, *img5;
アレイはコントローラで初期化されます -
-(void)loadStarImageSet
{
NSString *imagePath = [[NSBundle mainBundle] pathForResource:AWARD_STAR_0 ofType:@"png"],
*imagePath1 = [[NSBundle mainBundle] pathForResource:AWARD_STAR_1 ofType:@"png"],
*imagePath2 = [[NSBundle mainBundle] pathForResource:AWARD_STAR_2 ofType:@"png"],
*imagePath3 = [[NSBundle mainBundle] pathForResource:AWARD_STAR_3 ofType:@"png"],
*imagePath4 = [[NSBundle mainBundle] pathForResource:AWARD_STAR_4 ofType:@"png"],
*imagePath5 = [[NSBundle mainBundle] pathForResource:AWARD_STAR_5 ofType:@"png"]
;
img = [[UIImage alloc] initWithContentsOfFile:imagePath];
img1 = [[UIImage alloc] initWithContentsOfFile:imagePath1];
img2 = [[UIImage alloc] initWithContentsOfFile:imagePath2];
img3 = [[UIImage alloc] initWithContentsOfFile:imagePath3];
img4 = [[UIImage alloc] initWithContentsOfFile:imagePath4];
img5 = [[UIImage alloc] initWithContentsOfFile:imagePath5];
if(imageSet != nil)
{
[imageSet release];
}
imageSet = [NSArray arrayWithObjects:img, img1, img2, img3, img4, img5, img, nil];
[imageSet retain];
}
ビューが表示されると、これが起こります-
(void)viewDidAppear:(BOOL)animated
{
[self processResults];
[self setCorrectImage];
[self animateStar];
}
-(void)setCorrectImage
{
// It crashes on this assignment below!!!!!
[imageSet replaceObjectAtIndex:6 withObject:img4]; // hard-coded img4 for prototype... it will be dynamic later
}
-(void) animateStar
{
//Load the Images into the UIImageView var - imageViewResult
[imageViewResult setAnimationImages:imageSet];
imageViewResult.animationDuration = 1.5;
imageViewResult.animationRepeatCount = 1;
[imageViewResult startAnimating];
}