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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:09:08+00:00 2026-06-18T01:09:08+00:00

I’m going to show in my app a sort of UIActivityIndicatorView while parsing several

  • 0

I’m going to show in my app a sort of UIActivityIndicatorView while parsing several JSON objects, inside a for () loop. I can’t figure WHERE I must place the [UIActivityIndicatorView startAnimating] and [UIActivityIndicatorView stopAnimating] to show the real END of parsing (at the end of the complete for () loop). This is the simplified code:

- (void)parseMethod {

// other stuff

        for (int i=0; i < [arrayJSON count]; i++) {

            NSURL *url = [NSURL URLWithString:
                          [NSString stringWithFormat:
                           @"http://WWW.REMOTESERVERWITHJSONSOURCE.NET/%@",[arrayJSON objectAtIndex:i]]];

            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

                NSMutableDictionary *arrayMain = [JSON objectForKey:@"main"];
                NSMutableDictionary *arrayMain2 = [JSON objectForKey:@"main2"];
                [arrayA1 addObject:[arrayMain valueForKey:@"A1"]];
                [arrayA2 addObject:[arrayWind valueForKey:@"A2"]];

                // HERE FINISH PARSING AFJSONREQUESTOPERATION
                // IF I PUT HERE [UIActivityIndicatorView stopAnimating] IT SHOWS AT THE END OF FIRST for () LOOP

                [table reloadData];
                [table scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]
            }
                                                                            failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
                                                                            NSLog(@"%@", [error userInfo]);
                                                                        }];
            [operation start];
            // HERE START PARSING AFJSONREQUESTOPERATION
            [UIActivityIndicatorView startAnimating] 
        }

    // HERE FINISH THE for () LOOP ??
    // IF I PUT HERE [UIActivityIndicatorView stopAnimating] IT SHOWS AGAIN AT THE END OF FIRST for () LOOP

} 

    // HERE FINISH THE parseMethod ??
    // IF I PUT HERE [UIActivityIndicatorView stopAnimating] IT SHOWS AGAIN AT THE END OF FIRST for () LOOP

    }

As u can see, I can’t find the true place to put [UIActivityIndicatorView stopAnimating], ‘cos everywhere it stop at the end of the FIRST parsing (first for () loop): so, there is a way to WAIT the complete for () loop to call [UIActivityIndicatorView stopAnimating] (or another method) AFTER the ENTIRE cycle? Thanks!

ALTERNATIVE
Maybe the parsing is so fast that I can’t see the UIActivityIndicatorView appearing and loading? In this case, WHERE I must put a sort of timer (or the sleep(unsigned int)) to wait a few seconds before it disappear?

  • 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-18T01:09:10+00:00Added an answer on June 18, 2026 at 1:09 am

    Solution is to

    1. Simplify the code so that is obvious what is being done there (declaring the blocks beforehand)

    2. Count how many requests are running and perform the global actions only when all the requests are completed.

    typedef void (^AFJSONSuccessBlock) (NSURLRequest *request, NSHTTPURLResponse *response, id JSON);
    typedef void (^AFJSONFailureBlock) (NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON);
    
    [UIActivityIndicatorView startAnimating];
    
    __block int numRequests = [arrayJSON count];
    
    AFJSONSuccessBlock onSuccess = ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {   
        [...]
    
        numRequests--;
    
        if (numRequests == 0) {
            [UIActivityIndicatorView stopAnimating];
        }
    };
    
    AFJSONFailureBlock onFailure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        [...]
    
        numRequests--;
    
        if (numRequests == 0) {
            [UIActivityIndicatorView stopAnimating];
        }
    };
    
    for (NSString* jsonPath in arrayJSON) {
        NSString* absolutePath = [NSString stringWithFormat:@"http://WWW.REMOTESERVERWITHJSONSOURCE.NET/%@", jsonPath];
        NSURL *url = [NSURL URLWithString:absolutePath];
    
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        AFJSONRequestOperation *operation;
        operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                                    success:onSuccess
                                                                    failure:onFailure];
        [operation start];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am using Paperclip to handle profile photo uploads in my app. They upload

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.