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

  • Home
  • SEARCH
  • 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 8049853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:54:04+00:00 2026-06-05T06:54:04+00:00

I’m having some trouble with sleep(). I have 10 UIButtons which are connected to

  • 0

I’m having some trouble with sleep(). I have 10 UIButtons which are connected to the same IBAction called “buttons:”. Now, the IBAction method should make all the buttons unenabled and turn the background color of them to red and then call a method called “nextButtonToEnable” which first has a sleep(1) and then a random int thats used by a switch which turns 1 of the buttons enabled and blue instead of red. Now to the problem, I want all the buttons to turn red when pressed and then after 1 sec delay another button will become blue, but that doesn’t happen, what really happens is that when i press the blue button it stays blue during the whole delay of 1 sec and then it turns red and another button is turns blue.

here is my code

.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    IBOutlet UIButton *b1;
    IBOutlet UIButton *b2;
    IBOutlet UIButton *b3;
    IBOutlet UIButton *b4;
    IBOutlet UIButton *b5;
    IBOutlet UIButton *b6;
    IBOutlet UIButton *b7;
    IBOutlet UIButton *b8;
    IBOutlet UIButton *b9;
    IBOutlet UIButton *b10;
}
-(void)nextButtonToEnable;


@end

.m:

-(IBAction)buttons:(id)sender {
b1.enabled = NO;
b2.enabled = NO;
b3.enabled = NO;
b4.enabled = NO;
b5.enabled = NO;
b6.enabled = NO;
b7.enabled = NO;
b8.enabled = NO;
b9.enabled = NO;
b10.enabled = NO;
b1.backgroundColor = [UIColor redColor];
b2.backgroundColor = [UIColor redColor];
b3.backgroundColor = [UIColor redColor];
b4.backgroundColor = [UIColor redColor];
b5.backgroundColor = [UIColor redColor];
b6.backgroundColor = [UIColor redColor];
b7.backgroundColor = [UIColor redColor];
b8.backgroundColor = [UIColor redColor];
b9.backgroundColor = [UIColor redColor];
b10.backgroundColor = [UIColor redColor];

[self nextButtonToEnable];
}

-(void)nextButtonToEnable {

sleep(1);

int nextButton = rand() % 10;

switch (nextButton) {
    case 0:
        b1.enabled = YES;
        b1.backgroundColor = [UIColor blueColor];
        break;
    case 1:
        b2.enabled = YES;
        b2.backgroundColor = [UIColor blueColor];
        break;
    case 2:
        b3.enabled = YES;
        b3.backgroundColor = [UIColor blueColor];
        break;
    case 3:
        b4.enabled = YES;
        b4.backgroundColor = [UIColor blueColor];
        break;
    case 4:
        b5.enabled = YES;
        b5.backgroundColor = [UIColor blueColor];
        break;
    case 5:
        b6.enabled = YES;
        b6.backgroundColor = [UIColor blueColor];
        break;
    case 6:
        b7.enabled = YES;
        b7.backgroundColor = [UIColor blueColor];
        break;
    case 7:
        b8.enabled = YES;
        b8.backgroundColor = [UIColor blueColor];
        break;
    case 8:
        b9.enabled = YES;
        b9.backgroundColor = [UIColor blueColor];
        break;
    case 9:
        b10.enabled = YES;
        b10.backgroundColor = [UIColor blueColor];
        break;

    default:
        break;
}
}

So its like the sleep is between b1.enabled = NO; and b1.backgroundColor = [UIColor redColor];.

How do i fix this because i haven’t found anything on the internet. Mostly because I dont have a single clue what to search for :P.

  • 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-05T06:54:06+00:00Added an answer on June 5, 2026 at 6:54 am

    You should probably be using performSelector:withObject:afterDelay: and not sleep()

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.