Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:53:50+00:00 2026-06-17T01:53:50+00:00

I have a routine that draws a gearwheel using CoreGraphics and drawRect. I used

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:53:51+00:00Added an answer on June 17, 2026 at 1:53 am

    The iPhone only updates the screen 60 times a second no matter how often you call setNeedsDisplay. Your loop is going to execute in less than 1/60th of a second. That’s why you only will see the last state.

    If you want to show all four states through one button press then you could use a timer or performSelector: afterDelay to show all four states. A little more complicated but there you go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a routine procedure DrawStuff(ACanvas: TCanvas; const ARect: TRect) that draws something to
I have this routine that works well, but it messes up as it counts
I have a routine that examines thousands of records looking for discrepancies. This can
I have a routine that dynamically changes a select list's selected option when the
I'm developing an MVC application and I have a routine that gets the currently
I have a jquery routine that calls an MVC action which will do a
I have a bunch of code in a routine that looks a bit like
Good Day, I have a simple working routine in Perl that swaps two words:
I have a web application I've developed that has a fairly complex save routine.
I have developed a quite large application using MFC. Naturaly, I used GDI for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.