1

I have an ipad app is written in xcode 5.x and I have

1 controller with a tableview and UIProgressView 1 class that does syncronious download (NSObject class)

1.) The controller calls the donwload function from the download class 2.) The function should update the progress bar

As far as my research goes that should be done by using app delegate to access the Controller from the NSObject class

The problem is that the progressbar does not update at all if I nslog the values they are correct 0.xxxx (float value)

My code so far:

MyAppDelegate.h

@property (strong, nonatomic) UIViewController * activeController;

MyTableViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.activeController = self;
}

MyDownloadClass.m

    - (NSMutableArray *)uvoz:(NSString *)ident{
        @autoreleasepool {
    NSUInteger max = [jsonArray count], i = 0;

                MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
                MyTableViewController *topView = (MyTableViewController *)appDelegate.activeController;
                topView.uiProgress.progress = i;

                for (NSDictionary *line in jsonArray) {
         i++;
         [topView.uiProgress setProgress:(((float)i - 1 ) / (max-1)) animated:YES];
        }     
    }
}
Jester
  • 2,682
  • 5
  • 27
  • 40
  • Just to be curious, have you tried wrapping the setProgress-call with `dispatch_async(dispatch_get_main_queue(), ^{ [topView.uiProgress setProgress:(((float)i - 1 ) / (max-1)) animated:YES]; });`? Just to make sure that the download actually are made synchronously. Also, if the download are in fact made synchronously the chances are big that you are blocking the UI thread from doing any work and hence, the progress-bar will not update. EDIT: You did not submit enough code to actually see how the uvoz method are being used so i'm just guessing ;) – Alexander W Aug 04 '14 at 08:09
  • I just started working with ios so bare with me :). Just to clerify @AlexanderW If I block the UI thread (Witch I am ) cos the uvoz method is called by a click of a button. That means nothing will update till it is done? – Jester Aug 04 '14 at 08:16
  • 1
    It's cool Jester =) The button might light up, but yes, nothing will be done if you are currently downloading in the UI-thread. I'd pone you to use a library like AFNetworking to get as much as possible out of this. That library is very feature-rich and has lots of callbacks that make this kind of task as simple as going buying ice cream. – Alexander W Aug 04 '14 at 08:19
  • Thank you will look into it – Jester Aug 04 '14 at 08:23

0 Answers0