I’m using this call to switch image every 4 seconds:
- (void) settheimage {
cur+=1;
waits=0;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(settheimage) object:nil];
jpg = [NSString stringWithFormat:@"%@/%@_%d",current_anim,current_anim, cur];
img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jpg ofType:@"jpg"]];
[self performSelector:@selector(settheimage) withObject:nil afterDelay:4.0];
}
it works on the first image but after that it crashes.
i don’t want to use uiimage animation because i have a lot of images and the loading of the uiimage animation takes a lot of time.
I would guess that
current_animis (auto)released by the time your method is called, leading to a dangling pointer and crash (EXC_BADACCESS, I suppose?). You need to retain it manually, make it a retained property, or start using ARC.In either case, you should read something about memory management.