views:

17

answers:

0

please read the code in my viewcontroller

-(void)StartAnimation
{
 if (self.myimgarray == nil) {
  self.myimgarray = [NSMutableArray arrayWithCapacity:0];
 }
 UIImage *img;
 for (int i=0; i<=17; i++) {
  img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"a_expand_%d.png",i] ofType:nil]];
  [self.myimgarray addObject:img];
  //[img release];
  //NSLog(@"%@'s retain count is %d",@"img",[img retainCount]);
 }
 mainImgview.animationImages = self.myimgarray;
 [mainImgview startAnimating];
 isAnimating = YES;
}

-(void)StopAnimation
{
 [mainImgview stopAnimating];
 [mainImgview.animationImages release];mainImgview.animationImages = nil;


 isAnimating = NO;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 if (isAnimating) {
  [self StopAnimation];
 }
 else {
  [self StartAnimation];
 } 
}

it can start well, but when I try to touch it again to stop it, it gives a bad_access error when doing [maiImgview.animationImages release];

also is my code right for the retain, release pair? i'm confused alot. especially for the commented [img release] part. should I comment it out? coz I got a advice from build/analize, it tells me to comment it out.