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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:10:24+00:00 2026-06-02T00:10:24+00:00

I would like to update a progressbar while i am instantiating some ui elements

  • 0

I would like to update a progressbar while i am instantiating some ui elements that takes some times. I first create my view during the viewLoad method and add my progress bar there. Once my view appeared in the viewDidAppear method I am making several uikit objects instantiation but i would like to update the progress bar in the mean time. I am not sure how to proceed since everything should happen in the main thread as it is ui elements.

Here is part of my code:

-(void) viewDidAppear:(BOOL)animated
{
    // precompute the source and destination view screenshots for the custom segue
    self.sourceScreenshotView = [[UIImageView alloc] initWithImage:[self.view pw_imageSnapshot]];

    [self.progressBar setProgress:.3];


    SCLViewController *rvc = [[SCLViewController alloc] init];
    UIView *destinationView = rvc.view;
    destinationView.frame = CGRectMake(0, 0, kWidthLandscape, kHeightLandscape);


    self.destinationScreenshotView = [[UIImageView alloc] initWithImage:[destinationView pw_imageSnapshot]];

    [self.progressBar setProgress:.5];

}

In the above code I just need to create two screenshots of views to use them later on. The problem is that i only see the last update (.5) when setting the progress to the progress bar. What is the proper way to do this update?

  • 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-02T00:10:25+00:00Added an answer on June 2, 2026 at 12:10 am

    You can use the performSelectorInBackground:withObject: method in order to instantiate your heavy views. That method (the one that instantiates your views) will have to set your progress bar progress in the main thread.

    So your code would look something like this:

    - (void)viewDidAppear:(BOOL)animated
    {
        [self performSelectorInBackground:@selector(instantiateHeavyViews) withObject:nil];
    }
    
    - (void)instantiateHeavyViews
    {
        self.sourceScreenshotView = [[UIImageView alloc] initWithImage:[self.view pw_imageSnapshot]];
        [self performSelectorOnMainThread:@selector(updateMyProgressView:) withObject:[NSNumber numberWithFloat:0.3f] waitUntilDone:YES];
    
        SCLViewController *rvc = [[SCLViewController alloc] init];
        UIView *destinationView = rvc.view;
        destinationView.frame = CGRectMake(0, 0, kWidthLandscape, kHeightLandscape);
    
        self.destinationScreenshotView = [[UIImageView alloc] initWithImage:[destinationView pw_imageSnapshot]];
    
        [self performSelectorOnMainThread:@selector(updateMyProgressView:) withObject:[NSNumber numberWithFloat:0.5f] waitUntilDone:YES];
    }
    
    - (void)updateMyProgressView:(NSNumber *)progress
    {
        [self.progressBar setProgress:[progress floatValue]];
    }
    

    Edit: of course, it won’t animate your progress bar (I don’t know if that is what you wanted). If you want it to move on while your views are being created, you should use a delegate to be notified of the progress, and this can be a bit harder. This way you would be able to update the progress bar every time the delegate is notified.

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

Sidebar

Related Questions

i have a program that takes some time creating pdf files i would like
I would like to update (change the content) some part of the webpage without
I would like to update my current SB2 theme Sunburst so that the current
I would like to update some data with JSON when the user clicks on
I'm making an update to our database and would like to update rows that
I want to display a progress bar while doing some work, but that would
I would like to dynamically update the ProgressBar Color, in order to match with
I would like to update some images (gif) in my application. After replacing the
I have some code that moves files around and would like to implement a
I would like to update 3 rows of a single table, with different values

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.