0

In my project am downloading data from server, downloading code is in App Delegate.m file and once am passing downloading status(in bytes) to NSNotification object. In my ViewController am trying to update UIProgressView using the above downloading status. When i log Downlaoding status (bytes downloaded) am getting correct value. But when i tried to show that in UIProgressView and its not showing anything.

Code

App delegate.m

 ViewController *viewC=[[ViewController alloc]init];
[viewC postNotificationWithValue:bytesDownloaded:totalSize];

In ViewController.m

- (void)viewDidLoad
{
    _progreeView.progress = 0.0; //UIProgressView

    NSString *notificationName = @"MTPostNotificationTut";

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(useNotificationWithString:)
     name:notificationName
     object:nil];
}





- (void)postNotificationWithString:(NSUInteger )current:(NSUInteger )total {


   //   NSLog(@"%f",(double)current/(double)total);
    float status=(double)current/(double)total;
    _downloadStatus.text=[NSString stringWithFormat:@"%f",status];

[_progreeView  setProgress:status animated:YES];
}

and my UIProgressbar is not updating at all. Pls help me

Naveen Kumar
  • 177
  • 2
  • 2
  • 11
  • You just create a viewController and than setup it's slider value? And what about the view and viewController initialization process? You have to setup the viewController's view to be presented before you update the progress indicator on an animated way... Please, start to build a simple iOS app based on http://www.raywenderlich.com/1797/ios-tutorial-how-to-create-a-simple-iphone-app-part-1 – Balazs Nemeth Nov 26 '14 at 10:11
  • i have lots of contents in viewcontroller and delegaet but i show only relevent contents here – Naveen Kumar Nov 26 '14 at 10:13

1 Answers1

1

Have u check if the _progreeView isn't nil?! Why not load the ViewController from nib :

NSArray *viewArray = [[NSBundle mainBundle] loadNibNamed:@"ViewController"
                                                   owner:self 
                                                  options:nil];

ViewController *vc = (ViewController*)[viewArray objectAtIndex:0];

Anyway, Without go too deep with your code, I think that the problem is because that u don't update the UI from the main thread. Make sure that u updating:

[_progreeView  setProgress:status animated:YES];

From the MAIN thread.

Any UI changes must be on the main thread - Remember that!

So u can wrap that like:

dispatch_async(dispatch_get_main_queue(), ^{
  [_progreeView  setProgress:status animated:YES];
}
gran33
  • 12,421
  • 9
  • 48
  • 76