views:

345

answers:

2

I am currently working with the iPhone SDK.

I have a NSTimer that changes the background image of a UIButton. Once this is complete, it will trigger the same action again (reset the NSTimer) for a predetermined number of times.

My problem is that if my NSTimer is set to execute more than once per second. (0.75, say) The background image wont change.

I am using NSLog to check that the event fires. But the button image will just remain in its original state.

Is there any way to change the background image more often than once per second?

This is my timer :

[NSTimer scheduledTimerWithTimeInterval: tmpLvlSpeed
                                     target: self
                                   selector: @selector(simPressRed:)
                                   userInfo: nil
                                    repeats: NO];

And the code to change the image:

[btnRed setImage:[UIImage imageNamed:@"btn_red.png"] forState:UIControlStateNormal];

if tmpLvlSpeed is less than 1.0, the button image will never change. Even though the simPressRed function will still fire.

Any clues? Is there an update cycle I can modify?

A: 

Have you tried to use setNeedsDisplay?

[button setNeedsDisplay];
epatel
Thanks! that did the trick.
beta.services
A: 

how many images do you have? From what you gave us, you only have one image, so no duh the image won't change. Please post the code you have so we can further help you

Matt S.
The buttons were created using InterfaceBuilder, so I only had the one line of code to change the image.
beta.services
ok, but how many images do you have?
Matt S.
Its just the two. the original state and then the active one that I was trying to change it to.
beta.services