1

I have this code in a button click [NSThread detachNewThreadSelector: @selector(spinBegininapp) toTarget:self withObject:nil]; to show a activity indicator for user that the background thread is running ,i put this code to enable the activity-indicator

- (void)spinBegininapp
{
    _activityindictor.hidden = NO;

}

and it works fine,when i click the button it shows the activity-indictor animating ,when the thread goes it hides the activity-indicator,but my need is to show a progressView instead of activity-indicator,it progresses according to the thread,and if the thread finishes it need to reach progress completely and self hide.is that possible .

Oleksi
  • 12,947
  • 4
  • 56
  • 80
stackiphone
  • 1,245
  • 3
  • 19
  • 41

2 Answers2

6
#pragma mark - Loading Progress

static float progress = 0.0f;

-(IBAction)showWithProgress:(id)sender {
   progress = 0.0f;
   _progressView.progress = progress;
   [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3];
}

-(void)increaseProgress {
   progress+=0.1f;
   _progressView.progress = progress;    
   if(progress < 1.0f)
     [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3];
   else
    [self performSelector:@selector(dismiss) withObject:nil afterDelay:0.2f];
}

-(void)dismiss {
   [self progressCompleted];
}

now call the following function whenever/where ever you want to show progress

[self showWithProgress:nil]; 

progress range lies between 0.0 and 1.0

1.0 means 100%

LeoSarena
  • 189
  • 2
  • 8
3

you can add a progress view no doubt but usually it used for definite quantities like time or data.. for eg. If you are downloading a 2mb file then you can always tell how much data you have downloaded and show the in the progress view as a factor. So if something similar is happening inside your thread you can use this..

UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:whateverStyle];
    progressView.progress = 0.75f;
    [self.view addSubview: progressView]
    [progressView release];

you just need to update your progress as the value changes.... hoping this helps.

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • yes u r correct,i struck here for update my progress as the value changes.i put this code but no luck filepercentage = (float)1/(float)10; progressview.progress = filepercentage; int p = 100 *filepercentage; NSString *percent = [NSString stringWithFormat: @"%d %%",p]; – stackiphone Mar 08 '12 at 08:32
  • "filepercentage = (float)1/(float)10" what are you doing here? and exactly what error are you facing...? – Ankit Srivastava Mar 08 '12 at 08:43
  • is the progressview visible? and if yes how often do you update the progressview? – Ankit Srivastava Mar 08 '12 at 08:58
  • no its not visible,but when the thered goes on it will visible.but no update of progress – stackiphone Mar 08 '12 at 09:13