Quote:
Originally Posted by NeoNate
Thanks for Joe and Meomix23f for their help.
For anyone who may refer to this thread in the future I have supplied the full solution below:
Code:
/* HEADER */
NSMutableArray *myArray;
@property (nonatomic, retain) NSMutableArray * myArray;
/* MAIN */
@dynamic myArray;
for(int i = 0; i < 50; i++)
{
UIImageView * myImageView = [[UIImageView alloc] init];
[myArray addObject:myImageView];
[myImageView release];
}
UIImageView *imageView = [myArray objectAtIndex:0];
imageView = [self newPieceViewWithImageNamed:@"myImage.png" atPostion:CGPointMake(200,400)]; [self addSubview:imageView];
imageView.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
imageView.layer.zPosition = 100;
[imageView release];
|
I am using C array like this:
.h:
UIImageView *imgStone[50];
and in .m with my code:
for (int i=0; i<50; i++)
{
imgStone[i] = [[UIImageView alloc] initWithImage:StoneFileName];
imgStone[i] = CGRectMake(x, y);
[self.view addSubview:imgStone[i]];
[imgStone[i] release];
}
but it is strange, since I've released the imgStone array, I still can move these imgStone by CGPointMake:
imgStone[i].center = CGPointMake(new_x, new_y, width, height);
Just curious if this is correct way? because my app runs quite smooth, but I found out that there is memory leak. If this is not a proper way, then how should I do? I have created another version which is using:
.h:
NSMutableArray *imgStoneArray;
UIImageView *imgStone;
.m:
for(int i=0;i<50;i++)
{
imgStone = [[UIImageView alloc] initWithImage:StoneFileName];
imgStone.frame = CGRectMake(x, y, width, height);
[imgFishArray addObject:imgFStone];
[self.view addSubview:imgStone];
[imgFish release];
}
then move Stones:
for(int i=0;i<50;i++)
{
UIImageView *loadedImage = [[UIImageView alloc] init];
loadedImage = [imgStoneArray objectAtIndex:i];
loadedImage.center = CGPointMake(new_x, new_y);
[loadedImage release];
}
the imgStone moves by a timer (0.2 second)
but the latter one crashed, I don't know what was wrong. Can anyone help on this? which way is better?