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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:59:38+00:00 2026-05-28T16:59:38+00:00

I’m downloading some pictures and have created a progress bar. I’m using asynchronous mode

  • 0

I’m downloading some pictures and have created a progress bar. I’m using asynchronous mode with NSURLConnection and initiate about 15 pictures downloads at the same time. During the initiation i call didStartLoadImages and the bar is successfully set to 0 width on the screen.

Now the problem start, when one of the images is completed it will call didLoadImageWithTotalPercentCompleted: and update the bar with the current percent. It works perfectly and the logs write nicely Updating frame to: 20% etc.. But the User Interface doesn’t update UNTILL all the images are completed?

I just notice that the main thread is blocked even tho it’s asynchronous?

Connection.m

-(void)loadImage:(NSString*)imageName numberOfImagesInSecquence:(int)nrOfImages {
    NSString *url = [NSString stringWithFormat:@"https://xxx.xxx.xxx.xxx/~%@/files/%@",site,imageName];

    /* Send URL */
    NSURL *urlToSend = [[NSURL alloc] initWithString:url];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlToSend];
    theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];

    self.receivedData = [NSMutableData data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    connectionIsLoading = NO;
    [[self delegate] didLoadImagesWithProcent:((float)1 - ((float)[imageArray count] / (float)nrOfImages)) *(float)100];
}

MainViewController.m

-(void)didStartLoadImages {
     /* Sets progress bar to 0% */
     [progressBar setBarWithPercent:0];
}


-(void)didLoadImageWithTotalPercentCompleted:(int)percent {
    if (percent == 100) {
        /* Done */
    } else {
        [progressBar setBarWithPercent:percent];
    }
}

ProgressBar.m

-(void)setBarWithPercent:(float)percent {
    int maxSizeOfBar = 411;

    [UIView beginAnimations:@"in" context:NULL];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationBeginsFromCurrentState:YES];

    CGRect frame = bar.frame;
    frame.size.width = maxSizeOfBar * (percent / 100) + 10;
    bar.frame = frame;
    NSLog(@"Updating frame to: %i",percent);

    [UIView commitAnimations];

}
  • 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-28T16:59:39+00:00Added an answer on May 28, 2026 at 4:59 pm

    This may be a problem with integer math truncation. Change your percentage value to a float or CGFloat instead of an int, and for all of your numbers write them like 100.0f instead of 100 to force C to treat them as floats instead of integers.

    Basically, in C if you do 1/2 it doesn’t give you 0.5, it gives you 0 because it uses integer math, and 2 doesn’t go into 1 a whole number of times. So when calculating a percentage, you really want to use floats because (1/100) * x will always be zero, but (1.0f/100.0f) * x will work correctly.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.