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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:14:43+00:00 2026-06-16T12:14:43+00:00

When moving from one view to another, I want in my second view as

  • 0

When moving from one view to another, I want in my second view as long as the image is being downloaded to see a spinner (so that the second view will open instantly not take any time at all, and the user waits for the spinner to finish).

Here is my code:

In the second View, the one that opens:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIActivityIndicatorView *spinner=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    spinner.center=CGPointMake(160.0,240.0 );
    spinner.hidesWhenStopped=YES;
    [self.view addSubview:spinner];
    [spinner startAnimating];

NSString *urlString=[NSString stringWithFormat:@"http://mysite.com/projects/test/test.jpg"];

    NSLog(@"URL is:%@",urlString);
    NSURL *url=[NSURL URLWithString:urlString];
    [more_info_image setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:url]]];

    [spinner stopAnimating];
}

I do not see the spinner at all. i do not think that this is because my internet connection is so fat. On the other hand, I see a little delay when a button is pressed and waiting for the view to open – like that it is that time when it tries to download the image.

I want to open the view, have the spinner, download the image and then let the spinner go away.

Must I change anything?

  • 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-16T12:14:45+00:00Added an answer on June 16, 2026 at 12:14 pm

    You might not be seeing the UIActivityIndicatorView since you are using [NSData dataWithContentsOfURL:url] on the main thread. This is blocking the main thread from displaying the UIActivityIndicatorView until after the image is downloaded, and by that point you are removing it.

    You might want to do something like:

    but make sure you define spinner in your *.h file for this to work.

    - (void)viewDidLoad
    {
       ...
    
       //This code will make downloadImage run in the background thread
       [self performSelectorInBackground:@(downloadImage) withObject:nil]
    
       ...
    }
    
    - (void) downloadImage{
        NSLog(@"URL is:%@",urlString);
        NSURL *url=[NSURL URLWithString:urlString];
        UIImage *downloadedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    
        //This code will make setImage run in the main thread since it is changing UI
        [more_info_image performSelectorOnMainThread:@selector(setImage:) withObject:downloadedImage waitUntilDone:NO];
        //This code will make stopAnimating run in the main thread since it is changing UI
        [spinner performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
    
    }
    

    The other way is to use Grand Central Dispatch and do something like:

    - (void)viewDidLoad
    {
    
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    
        UIActivityIndicatorView *spinner=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        spinner.center=CGPointMake(160.0,240.0 );
        spinner.hidesWhenStopped=YES;
        [self.view addSubview:spinner];
        [spinner startAnimating];
    
        //This is the new GCD code
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
        dispatch_async(queue, ^{
            //This code will run on a background thread
            NSString *urlString=[NSString stringWithFormat:@"http://mysite.com/projects/test/test.jpg"];
    
            NSLog(@"URL is:%@",urlString);
            NSURL *url=[NSURL URLWithString:urlString];
            UIImage *downloadedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    
            dispatch_sync(dispatch_get_main_queue(), ^{
                //this code runs on the main thread since it is UI changes
                [more_info_image setImage:downloadedImage];
    
                [spinner stopAnimating];
            });
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi we are using IBM Commerce Sever Moving from one view to another using
Will moving views from one schema to another have any adverse effect on performance?
In my application i am constantly moving from one control to another. I have
It seems that often I find that my code when moving either from one
I'm having trouble moving a website from one server to another. It seems to
Here i am moving the whole li elements from one list to another list.What
Trying to achieve any moving effect while appending an element from one to another
I have two objects: one that is moving by animation, and another that is
I want to implement layering of screens when transitioning from one screen to another.
I am developing one application.In that i want to move the uiview from right

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.