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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:36:40+00:00 2026-06-02T17:36:40+00:00

-(void)buttonClick:(id)sender { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; for(int i=0;i<500000000;i++) { //Simulates network activity } [UIApplication

  • 0
-(void)buttonClick:(id)sender
{    
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    for(int i=0;i<500000000;i++)
    {
        //Simulates network activity
    }
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

Theoretically, the network activity spinner in the top left corner of the screen should turn on, spin for a while, then turn off…however, it never shows up.

-(void)buttonClick:(id)sender
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    for(int i=0;i<500000000;i++)
    {
        //Simulates network activity
    }
    //[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

With “= NO” being commented out, I noticed that the program runs through the entire for loop, then after completion of the for loop, the spinner finally starts spinning.

-(void)viewWillAppear:(BOOL)animated
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
}

-(void)buttonClick:(id)sender
{
    for(int i=0;i<500000000;i++)
    {
        //Simulates network activity
    }
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

Now, when the view appears, the indicator starts spinning. When I click the button, it continues spinning while the loop is running. When the for loop ends, the spinner stops as expected.

-=-=-=-=-=-=-=-=-=-

My question is this, why won’t the spinner start spinning till after the for loop in the first 2 examples?

-=-=-=-=-=-=-=-=-=-

My thinking thus far:

In terms of why the spinner won’t start in this specific example…Perhaps it sends the message, but doesn’t get executed till after the for loop, because of how the compiled code works?

Perhaps the correct way of doing this is to enable the network activity indicator, then shoot off another thread that does the network activity, then that thread shoots a message back to the main thread when it’s done (presumably with the data it retrieved as well)

-=-=-=-=-=-=-=-=-

Any advice/answers are appreciated. Thanks in advance. Keep in mind this app is for iPad.

  • 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-02T17:36:42+00:00Added an answer on June 2, 2026 at 5:36 pm

    The UI will not update until the end of the current run loop. Your method currently blocks the main thread whilst doing it’s work, which does not give your program a chance to reach the end of the runloop.

    So what you need to do is take your long running task off of the main thread

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
    
        for(int i=0;i<500000000;i++)
        {
            //Simulates network activity
        }
    
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got this line of code here but its not working. private void Button_Click(object sender,
header file: private: vector<int*>* nums; public slots: void buttonClicked(); cpp file: NewWindow(){ int one
void FileManager::CloseFile(File * const file) { for (int i = 0; i < MAX_OPEN_FILES;
- (void)applicationDidFinishLaunching:(UIApplication *)application { // Create the navigation and view controllers RootViewController *rootViewController =
public partial class Form1 : Form { string[] id; private void button_Click(object sender, EventArgs
How to open an file's Properties dialog by a button private void button_Click(object sender,
I have this on a button: private void Button_Click(object sender, RoutedEventArgs e) { string
i have next code: private void button_Click(object sender, RoutedEventArgs e) { Thread t =
private void button_Click(object sender, RoutedEventArgs e) { var button = (Button) sender; var stackPanel
When I create buttons in C#, it creates private void button_Click(object sender, EventArgs e)

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.