I have a routine that draws a gearwheel using CoreGraphics and drawRect. I used a button to advanced the gears through the stages:
-(IBAction)advanceButtonPressed:(id)sender{
stage=stage+1;
if (stage==4) stage=0;
[self setNeedsDisplay];
}
The routine for drawing the gear is in drawRect, and the gear teeth are drawn in a new position depending on the vale of stage, which is passed to drawRect. In four steps, one per button press, the gear turns to its new position (one segment around the circle.)
I changed the buttonPressed routine to have it do the four stages in a loop, so I only need to press the button once, but it doesn't work:
-(IBAction)buttonPressed:(id)sender{
for (stage=0;stage<4;stage++){
NSLog(@"%i",stage);
[self setNeedsDisplay];
}
}
My NSLog shows that stage goes through its four values, just as it would in the earlier routine. But setNeedsDisplay is only executed once, (as a NSLog trace in drawRect confirms) so the gear is displayed in its final position but not the intermediate stages. It looks like setNeedsDisplay only executes when the button routine finishes, despite it being inside the loop.
Is there any way to force it to execute?