1

I am trying to upload data using POST method in ios application.I want to show progressbar indicator while uploading the data. I have progressbar in another view controller and NSURLConnection delegate methods in another class. I have tried as below.

 -(void)updateProgressBar:(float)progressBarValue {

      NSLog(@"What is the progress bar indicator %f",progressBarValue);
      [self     performSelectorOnMainThread:@selector(updateProgressOnMainThread) withObject:nil waitUntilDone:NO];
progressBarValueForMinThread = &progressBarValue;

  }

 - (void)updateProgressOnMainThread {

       progressBar.progress = *(progressBarValueForMinThread);

  }

Class containing NSURLConnection methods

  - (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{
       NSLog(@"bytesWritten %d",bytesWritten);
       NSLog(@"totalBytesWritten %d",totalBytesWritten);
       NSLog(@"totalBytesExpectedToWrite %d",totalBytesExpectedToWrite);
       progressedIndicator = ((float)totalBytesWritten / totalBytesExpectedToWrite);
       NSLog(@"DELEGATE PROGRESS INDICATOR %f",progressedIndicator);
       [objUpdatesController updateProgressBar:progressedIndicator];
}

"objUpdatesController" is the object of class containing progress bar. Any help is appreciated.

Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
user3162102
  • 105
  • 1
  • 10
  • Progress bar is not visible or it's not progressing? – Gaurav Srivastava Dec 24 '15 at 11:23
  • It is not progressing. viewdidload method: [progressBar setTransform:CGAffineTransformMakeScale(1.0, 5.0)]; progressBar.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2); progressBar.trackTintColor = [UIColor darkGrayColor]; progressBar.progressTintColor = [UIColor colorWithRed:1.000 green:0.869 blue:0.275 alpha:1.000]; progressBar.progress = 0.0; [self performSelectorOnMainThread:@selector(updateProgressBar:) withObject:nil waitUntilDone:NO]; [self.view addSubview:progressBar]; – user3162102 Dec 24 '15 at 11:28
  • The selector in which you have written the code for progressing needs to be called regularly. Please add > progressBar.progress = *(progressBarValueForMinThread); < in a timer handler. Use NSTimer. – Gaurav Srivastava Dec 24 '15 at 11:30
  • You need to add previous value to new value ... and assign it to the progress not just give it the current data sent. – user523234 Dec 24 '15 at 12:06
  • @GauravSrivastava , Thanks for immediate reply. I am sending the progressbar value from NSURLConnectiondelegate method "didSendBodyData: " .Its called only once, and it always sends value as 1, which makes progressbar completed, but step by step progressing is not happening. How to add newvalue to the existing value as that delegate method sends "1"!. When I add breakpoint all the three variables ie, bytesWritten ,totalBytesWritten,totalBytesExpectedToWrite shows same value, If bytesWritten and totalBytesExpectedToWriteare incremented step by step progress bar value can shown.How to acheive – user3162102 Dec 29 '15 at 05:19
  • 1
    Please check this - http://stackoverflow.com/q/24189092/5252706. Let me know if that doesnt help u. – Gaurav Srivastava Dec 29 '15 at 05:56
  • I have tried type casting by adding float ....... progressedIndicator = ((float)totalBytesWritten / totalBytesExpectedToWrite); progressedIndicator is of type float – user3162102 Dec 29 '15 at 06:13

0 Answers0