J'ai un extrait de code ici que je ne peux pas faire fonctionner.NSArray dans NSArray ne pas retourner l'image que je veux
NSUInteger i;
//NSMutableArray *textures = [[NSMutableArray alloc] initWithCapacity:kNumTextures];
//NSMutableArray *texturesHighlighted = [[NSMutableArray alloc] initWithCapacity:kNumTextures];
NSMutableArray *textures= [[NSMutableArray alloc] init];
for (i = 1; i <= kNumTextures; i++)
{
NSString *imageName = [NSString stringWithFormat:@"texture%d.png", i];
NSString *imageNameHighlighted = [NSString stringWithFormat:@"texture%d_select.png", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImage *imageHighlighted = [UIImage imageNamed:imageNameHighlighted];
//NSArray *pics = [[NSArray alloc] initWithObjects:(UIImage)image,(UIImage)imageHighlighted,nil];
NSArray *pics = [NSArray arrayWithObjects:image,imageHighlighted,nil];
[textures addObject:pics];
[pics release];
}
//select randomly the position of the picture that will be represented twice on the board
NSInteger randomTexture = arc4random()%([textures count]+1);
//extract image corresponding to the randomly selected index
//remove corresponding pictures from textures array
NSArray *coupleTexture = [textures objectAtIndex:randomTexture];
[textures removeObjectAtIndex:randomTexture];
//create the image array containing 1 couple + all other pictures
NSMutableArray *texturesBoard = [[NSMutableArray alloc] initWithCapacity:kNumPotatoes];
[texturesBoard addObject:coupleTexture];
[texturesBoard addObject:coupleTexture];
[coupleTexture release];
NSArray *pics = [[NSArray alloc] init];
for (pics in textures) {
[texturesBoard addObject:pics];
}
[pics release];
//shuffle the textures
//[texturesBoard shuffledMutableArray];
//Array with masks
NSMutableArray *masks= [[NSMutableArray alloc] init];
for (i = 1; i <= kNumMasks; i++)
{
NSString *maskName = [NSString stringWithFormat:@"mask%d.png", i];
UIImage *mask = [UIImage imageNamed:maskName];
//NSArray *pics = [[NSArray alloc] initWithObjects:mask,nil];
[masks addObject:mask];
//[pics release];
[maskName release];
[mask release];
}
//Now mask all images in texturesBoard
NSMutableArray *list = [[NSMutableArray alloc] init];
for (i = 0; i <= kNumMasks-1; i++)
{
//take on image couple from textures
NSArray *imgArray = [texturesBoard objectAtIndex:i];
UIImage *mask = [masks objectAtIndex:i];
//mask it with the mask un the array at corresponding index
UIImage *img1 =(UIImage *) [imgArray objectAtIndex:0];
UIImage *img2 =(UIImage *) [imgArray objectAtIndex:1];
UIImage *picsMasked = [self maskImage:(UIImage *)img1 withMask:(UIImage *)mask];
UIImage *picsHighlightedMasked = [self maskImage:(UIImage *)img2 withMask:(UIImage *)mask];
//Init image with highlighted status
TapDetectingImageView *imageView = [[TapDetectingImageView alloc] initWithImage:picsMasked imageHighlighted:picsHighlightedMasked];
[list addObject:imageView];
}
Le problème ici est que: img1 et img2, ne sont pas des images mais plutôt NSArray avec plusieurs entrées. Je ne peux pas comprendre pourquoi ... n'importe quel esprit frais ici pourrait me donner un indice.
merci beaucoup.
Vous devriez vraiment "accepter" une réponse. À mon avis, la réponse de @ stigi était juste. @stigi a fait tout son possible pour coder une réponse bien écrite et réutilisable. Veuillez cliquer sur la coche à gauche pour accepter. – Jann