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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:47:58+00:00 2026-05-13T22:47:58+00:00

My idea is to have a view that is showing the user when something

  • 0

My idea is to have a view that is showing the user when something is calculated behind the scenes. It is a view with a height of 30px containing an UIActivityIndicatorView and an UILabel showing what is beeing calculated right now.

I tried to implement it by having a ActivityHandler with these methods:

- (void)newActivityStarted{
    [self performSelectorOnMainThread:@selector(showActivityViewer) withObject:nil waitUntilDone:NO];
}

- (void)activityStopped{
    [self performSelectorOnMainThread:@selector(hideActivityViewer) withObject:nil waitUntilDone:NO];
}

- (void)changeInfoText:(NSString*)infoText{
    [activityView.infoLabel performSelectorOnMainThread:@selector(setText:) withObject:infoText waitUntilDone:NO];
}

Here are the methods that are called on the main thread:

-(void)hideActivityViewer{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate: self];
    [UIView setAnimationDidStopSelector:@selector(closeActivityViewer:finished:context:)];
    [activityView setFrame:CGRectMake(320, 10, 320, 30)];

    [UIView commitAnimations];
}

-(void)closeActivityViewer:(NSString*)id finished:(BOOL)finished context:(id)context{

    [activityView removeFromSuperview];
    [activityView release];
    activityView = nil;
}

-(void)showActivityViewer{

    activityView = [[BCActivityView alloc] initWithFrame:CGRectMake(320, 10, 320, 30)];
    [activityView.infoLabel setText:NSLocalizedString(@"WorkInProgressKey",nil)];

    [[(MyAppDelegate*)[[UIApplication sharedApplication] delegate] window] addSubview: activityView];

    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.2];
    [activityView setFrame:CGRectMake(0, 10, 320, 30)];

    [UIView commitAnimations];
}

The methods newActivityStarted, activityStopped, changeInfoText are called by a background thread that is calculating some time consuming data.

The time consuming thread will be opened like this:

NSInvocationOperation* operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(calculateData) object:nil];
[[[NSOperationQueue new] autorelease] addOperation:operation];
[operation release];

The calculation is done like this:

-(void) calculateData{
    [[ActivityIndicatorHandler instance] newActivityStarted];
    [[ActivityIndicatorHandler instance] changeInfoText:NSLocalizedString(@"InitializingForecastKey", nil)];

    //Do something time consuming

    [[ActivityIndicatorHandler instance] activityStopped];
}

The effect is, that the activity view is shown and hidden after the whole calculation is done. I expected the GUI to show the view and be responsible to user interaction while the calculation is done in the background. But even if I have a breakpoint in the calculation, the view will not be usable until the calculation thread finished its work, as well as the activity view is not shown… And I can’t figure out what’s wrong…

Has anybody an idea?

  • 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-13T22:47:58+00:00Added an answer on May 13, 2026 at 10:47 pm
    @implementation ActivityHandler;
    
    //....
    - (void)newActivityStarted{
        [self performSelectorOnMainThread:@selector(showActivityViewer) withObject:nil waitUntilDone:NO];
    }
    
    - (void)activityStopped{
        [self performSelectorOnMainThread:@selector(hideActivityViewer) withObject:nil waitUntilDone:NO];
    }
    
    - (void)changeInfoText:(NSString*)infoText{
        [activityView.infoLabel performSelectorOnMainThread:@selector(setText:) withObject:infoText waitUntilDone:NO];
    }
    
    
    - (NSInvocationOperation*)myOperation:
    {
        NSInvocationOperation* operation = [[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(calculateData) object:nil] autorelease];
        return operation;
    }
    

    In some other method, probably your app delegate, have a local queue set up in your initializer:

    NSOperaionQueue* aQueue = [[[NSOperationQueue alloc] init] retain];  //release in dealloc
    ActivityHandler* myHandler [[[ActivityHandler alloc] init] retain];  //release in dealloc
    
    Have a method to add ops to the queue:
    
    -(void)queueOperation:(NSInvocationOperation*)anOp;
    {
        [aQueue addOperation:anOp];
    }
    
    -(IBAction*)startCalcs:(id)sender;
    {
        [self queueOperation:[myHandler myOperation]];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple idea: I have two images that I want to merge, one is 500x500
The Idea I have a main PHP page that loads content in DIV's from
For the program idea I have, it requires that the software be written in
I'm building a Qt application that have about 30 different views (QWidgets). My idea
i have a view that only lists those nodes that have a certain workflow-status
I have a View that displays a DataGrid which is bound to an ObservableCollection
I would like to have a view that scrolls. The view would have a
I have a view to create a user as follows. <% using (Html.BeginForm(SaveUser, Security))
I have a view that I am trying to add to my ADO.NET Entity
I have a view that returns data like the following: 1 | Abita |

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.