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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:14:06+00:00 2026-06-11T08:14:06+00:00

My cocoa app needs to fetch data from network and then shows content in

  • 0

My cocoa app needs to fetch data from network and then shows content in the table view. So I add a spinning style of NSProgressIndicator to animate when the data is downloading. After that the animation of NSProgressIndicator stops and reloads the NSTableView. The strange thing is after the table view reloading, the content shown is not updated. Then If you scroll the table view, the content starts to show,just like:
enter image description here
(the small rectangle above is the frame for the NSProgressIndicator)

Below is my code:


- (void)loadOperationData
{   
    dispatch_async(dispatch_get_main_queue(), ^{
        [self _showIndicator];
    });

    [NSThread detachNewThreadSelector:@selector(getOperationLogProcess) toTarget:self withObject:nil];
}

- (void)_showIndicator
{
    if (indicator == nil) 
    {
        indicator = [[NSProgressIndicator alloc] init];
        [indicator setStyle:NSProgressIndicatorSpinningStyle];
        [indicator setUsesThreadedAnimation:NO];// I tried to comment this, but no use
        int width = 30;
        CGRect rect = CGRectMake(0, 0, width, width);
        NSRect selfRect = [_coverView frame];
        rect.origin.x = selfRect.size.width/2 - width/2;
        rect.origin.y = selfRect.size.height/2 - width/2;
        indicator.frame = rect;
        [_coverView addSubview:indicator];
    }
    
    [indicator setHidden:NO];
    [indicator startAnimation:self];
}

-(void)getOperationLogProcess{
    
    NSDictionary *tempResutDic = [WebServiceManager getOperationLog];//using synchronous ASIHttpRequest to download data
    if ([[tempResutDic objectForKey:@"resultCode"] intValue]==100) {
        self.operationLogArray = [tempResutDic objectForKey:@"items"];
        
        [self performSelectorOnMainThread:@selector(reloadTableview) withObject:nil waitUntilDone:YES];//refresh UI in main thread
    }
}

-(void)reloadTableview
{
    [indicator stopAnimation:self];
    [indicator setHidden:YES];
    [operationlogTable setEnabled:YES];
    
    if ([_coverView isHidden])
    {
        return;
    }
    
    self.lastUpdateDate = [NSDate date];
    
    [operationlogTable reloadData];
}

The -(void)loadOperationData is called by the mouse click event. And The reason why I put the -(void)_showIndicator in a dispatch block is that the indicator can’t be shown. I tried a lot and finally chose it.

I guess the problem ties closely to the way of showing indicator because If I commented the code about the indicator, the problem dismissed.

I really need the indicator to let user know they are waiting.So Please help me how to correctly use NSProgressIndicator.

Thanks!

  • 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-11T08:14:07+00:00Added an answer on June 11, 2026 at 8:14 am

    It caused by the multithread.

    In- (void)loadOperationData I use main block to show progress indicator and create a thread to fetch data in background. The block is run asynchronously and sometimes is after the -(void)reloadTableview.

    Finally, I keep - (void)loadOperationData is called in main thread and put the - (void)_showIndicator out of the block. Then it is fixed.

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

Sidebar

Related Questions

I am developing an application in cocoa,which needs to check whether that app is
I have a very simple Mac Cocoa app that just has a Web View
I'm working on a Cocoa Mac app where I need to display a window/view
My Cocoa app needs some small dynamically generated windows. How can I programmatically create
I'm trying to create a Cocoa app that needs to target Mac OS X
I've got a cocoa app that needs to do some work in a second
I need to send a distributed notification from my cocoa app to my firebreath
I am developing an app in Cocoa. I need to show a progress at
I have a basic Cocoa app with a custom NSCollectionView that overrides drawRect: to
I'm writing a Cocoa app in Objective C that's communicating with a webservice and

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.