I have a rather basic question. I have several(5) UIImageView images on
my screen. When I click a button, I want to change each image
to something else. I also want to play a sound as each image is changed.
So I basically want a clicking sound as each image changes.
The problem is, for some reason if I have say 5 images,
the sound gets played 5 times first and then the images change.
It’s like the images only refresh when control goes back to the
user for input.
How can I “force” it to refresh the images as soon as i tell it what image to display?
I’m new to the iphone/macworld, so go easy on me 🙂
Rick
That’s exactly what happens. The UI is updated on the main thread so no updates happen whilst your code is running.
In order to achieve what you want, you’re going to need timers. Take a look at the NSTimer documentation. You need to create a timer that fires a method to change your second image and then requeue a timer to change your third image. There is a convenient method to create a timer like you need:
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeatsthen, you have a method:
I’ll leave it to you to implement the method updateImage3: 😉
Running the updates like this gives the main thread a chance to update the UI.