I got an NSArray with 5 pictures. I want to display them one after the other in a loop. My code :
NSArray *tabImage = [[NSArray alloc] init];
tabImage = [[
If pictoImage is an UIImageView, @Hagelin's answer is the best way to go. Now, if pictoImage is not an UIImageView object then you will have to take a different approach and that definitely is not a loop.
Set an NSTimer with a desired time interval and invoke a method that updates pictoImage iterating over the tabImages. It should be something like this :-
- (void)setup {
...
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(updatePictoImage:)
userInfo:nil
repeats:YES];
...
}
- (void)updatePictoImage:(NSTimer*)theTimer {
static int i = 0;
if ( i > 20 ) {
pictoImage.image = [tabImages objectAtIndex:(i % 5)];
} else {
[theTimer invalidate];
}
}
This should update the pictoImage every 2 seconds with images in tabImages.