Tutorial :iPhone: UIImageView not showing images


I've got UIImageView drawn in my nib-file and it's connected to a imageView iboutlet. I can load single pictures which will show up very nicely, but when it comes to drawing many images separately as like an animation, images won't show. I've got drawImage() function which takes NSData-objects(image data) and draws it to a screen(imageView).

Main function has got for loop which loops 300 times as quickly as it can and each time it calls that drawImage function and passes different image data to it. Sometimes when I execute this code, last picture from that "animation" shows up, sometimes not at all. Maybe I need to schedule enough time for imageView so that the image can be shown?

Hope someone has some clues. Thanks in advance!


try something like

// create the view that will execute our animation       UIImageView* ImageView = [[UIImageView alloc] initWithFrame:self.view.frame];         // load all the frames of our animation       ImageView.animationImages = [NSArray arrayWithObjects:                                      [UIImage imageNamed:@"1.png"],                                   [UIImage imageNamed:@"2.png"],                                   [UIImage imageNamed:@"3.png"],                               nil];         // all frames will execute in 1.75 seconds       ImageView.animationDuration = 1.75;       // repeat the annimation forever       ImageView.animationRepeatCount = 0;       // start animating       [ImageView startAnimating];       // add the animation view to the main window       [self.view addSubview:ImageView];  


just couple minutes ago, after fighting this for about 6 hours I managed to get it work like I wanted.

This is the magic line that did it:

[self.imageView performSelectorInBackground:@selector(setImage:)                                    withObject:imageData];  

Thanks for the help! : )

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »