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 968015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:24:40+00:00 2026-05-16T02:24:40+00:00

I need help with some programming logic… I need to loop this method to

  • 0

I need help with some programming logic… I need to loop this method to display the math problem in my labels then sleep(5) and then loop again. Anything I’ve tried ends of freezing the program. PLEASE help! I’ve been tearing my hair out trying everything I know!

EDIT: I edited the code to this, After 3 seconds it fades away the label displaying the problem but then it crashed and the debugger displays 2010-08-06 10:43:27.776 Reactor [13444:207] modifying layer that is being finalized - 0x5c13500

//quickfire problems
-(void)simpleMath{ //"Tap when the answer is X"
    isTimeToTap = NO;
    int problemSelector = arc4random() % 4;

    NSArray *mathProblems = [[NSArray alloc] initWithObjects:@"6 - 1",@"2 + 3",@"3 x 2",@"3 x 1",@"2 x 4",nil]; //correct index 2
    NSArray *mathAnswers = [[NSArray alloc] initWithObjects:@"5",@"5",@"6",@"3",@"8",nil]; //correct index 2

    if ([mathAnswers objectAtIndex:problemSelector] == @"6") {
        isTimeToTap = YES;
    }

    if (ranBefore == NO) { //create labels

        //tell when to tap
        tapTellerTop.text = @"Tap when the answer is 6!";
        tapTellerBottom.text = @"Tap when the answer is 6!";

        //make bottom label
        mathDisplayBottom = [[UILabel alloc] initWithFrame:CGRectMake(15, 250, 242, 92)];
        mathDisplayBottom.font = [UIFont fontWithName:@"Helvetica" size: 96.0];
        mathDisplayBottom.textColor = [UIColor whiteColor];
        mathDisplayBottom.backgroundColor = [UIColor clearColor]; 
        [self.view addSubview: mathDisplayBottom];

        //make top label
        mathDisplayTop = [[UILabel alloc] initWithFrame:CGRectMake(55, 120, 242, 92)];
        mathDisplayTop.font = [UIFont fontWithName:@"Helvetica" size: 96.0];
        mathDisplayTop.textColor = [UIColor whiteColor];
        mathDisplayTop.backgroundColor = [UIColor clearColor];
        [self.view addSubview: mathDisplayTop];
        //rotate top label
        mathDisplayTop.transform = CGAffineTransformMakeRotation(180.0 /180.0 * M_PI);
    }
    //if ran before just update the text 
    mathDisplayBottom.text = [mathProblems objectAtIndex:problemSelector];
    mathDisplayTop.text = [mathProblems objectAtIndex:problemSelector];

    ranBefore = YES; //if its here. its been ran.

    //run timer wait for (3) then loop again until userTaps = YES
    [self performSelector:@selector(simpleMath) withObject:nil afterDelay:3.0f];

    [mathProblems release];
    [mathAnswers release];
    [mathDisplayBottom release];
    [mathDisplayTop release];
}
  • 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-05-16T02:24:41+00:00Added an answer on May 16, 2026 at 2:24 am

    Sleep will stop your application from running or responding at all. Here is a quick partial example of a view controller you could use. This assumes you wire up the tap button and only uses one of the labels, etc. but you can play around with it. Also, this won’t deal with memory issues or anything, so you’d add support for that.

    But, once this view controller is created and the view installed, the math problem will update every 5 seconds. If the user presses the button and the answer is valid, we log a success message, otherwise we log fail message.

    @interface myMathController : UIViewController {
        NSArray* mathProblems;
        NSIndexSet* validIndexes;
        NSUInteger currentIndex;
    
        NSTimer* timer;
    }
    
    @property(nonatomic,assign) IBOutlet UILabel* mathDisplayLabel;
    
    - (void)updateProblem:(NSTimer*)timer;
    - (IBAction)userTap;
    
    @end
    
    @implementation myMathController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        mathProblems = [[NSArray alloc] initWithObjects:@"6 - 1",@"2 + 3",@"3 x 2",@"3 x 1",@"2 x 4",nil];
        // Add all valid answers
        NSMutableIndexSet* tempIndexes = [[NSMutableIndexSet alloc] init];
        [tempIndexes addIndex:2];
        validIndexs = [tempIndexes copy];
        [tempIndexes release];
    
        timer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:5.0 target:self selector:@selector(updateProblem:) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    }
    
    - (void)updateProblem:(NSTimer*)timer
    {
        currentIndex = arc4random() % [mathProblems count];
        [mathDisplayLabel setText:[mathProblems objectAtIndex:currentIndex]];
    }
    
    - (void)userTap
    {
        if( [validIndexes containsIndex:currentIndex] ) {
            NSLog(@"This user is SMART!");
        } else {
            NSLog(@"This user needs more work!");
        }
    }
    
    - (void)dealloc
    {
        [timer invalidate];
        [timer release];
        [mathProblems release];
        [validIndexes release];
        [super dealloc];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with this problem in implementing with XSLT, I had already implemented
I need some logic/programming help with reading more than one record from a text
I'm new programming in shell and I need some help with this code... Buildname=
In need some help with this little programming .. I just got 3 errors
I am a newbie with iphone programming. I need some help with this code.
I'm new to web programming, so I need some help. I am writing a
Need some help to solve this. I have a gridview and inside the gridview
Need some help gathering thoughts on this issue. Our team is moving ahead with
I'm a newbie to programming and need some help with the set of fixers
Hi I am a newbe to bash programming and need some help. I am

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.