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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:17:04+00:00 2026-05-31T13:17:04+00:00

I have a UIView *loadingView that simply has a black BG and a UIActivityIndicator

  • 0

I have a UIView *loadingView that simply has a black BG and a UIActivityIndicator. I want to add this to my view, and then sleep the thread for a couple seconds:

[self.window addSubview:loadingView];
loadingView.hidden=NO;
sleep(2);

Apparently, this isn’t enough time to add the view-the thread sleeps but the view isn’t added, and only appears after the 2 seconds. So I tried something like this:

-(void)sleep
{
    sleep(2);
}

[self.window addSubview:loadingView];
loadingView.hidden=NO;
[self performSelector:@selector(sleep) withObject:nil afterDelay:0.01];

This displays the view before the sleep, which is the desired result. However, under these 3 lines there are several lines of code that I don’t want executed until after the sleep, and within the 0.01 seconds, all those lines are executed.

  • 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-31T13:17:04+00:00Added an answer on May 31, 2026 at 1:17 pm

    Why on earth are you sleeping the main thread for 2 seconds? Normally that’s a horrible idea, because your app will become completely unresponsive for 2 seconds.

    You have the right idea in using performSelector:withObject:afterDelay:. But there is no way to get around the fact: if you want something to happen after that delay, then it has to go in the method called after the delay. Just move those other lines of code after the sleep().

    (And really, if you want something to happen after two seconds, just use performSelector:withObject:afterDelay: with a delay of two seconds.)

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

Sidebar

Related Questions

I have a UIView subclass ( CustomView for purposes of this question) that has
I have a UIView that has several UIImageViews as subviews. Each of these subviews
I have a UIView that I want to load when the user clicks a
I have a UIView in which I added a UITapGestureRecognizer . Inside that view
I have a UIView that has 3 sub-views: a header, a center panel, and
I have a UIView that has an image and some buttons as its subviews.
I have a UIView class that I am using to have a CALayer. This
I have a UIView in a table view section header that I would like
I have a viewController that has a tableView and a custom loading UIView that
I have a UIView subclass that has the following in drawRect: for(int j=0; j<[myArray

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.