views:

88

answers:

0

I have a UIProgressView added to self.view as subview. I have a UITableView with rows loaded. I need image in every row but I don't want the app to wait for all of them, so I decide to run NSThread with loading images process. When I try to update progress of the UIProgressView from inside my thread - it doesn't get updated. Do I need to implement some delegates maybe?

Initialization

    progressView = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
    [progressView setFrame:CGRectOffset(CGRectMake(0, 0, 320, 8), 0, 1)];
    [self.view addSubview:progressView];

Then I run my thread

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [progressView setProgress:0.0];
    NSThread *myThread = [[NSThread alloc] initWithTarget:self
                                                 selector:@selector(imageLazyLoading)
                                                   object:nil];

    [myThread start];
    [pool release];
    [myThread release];

Then I try to update it

CGFloat pr;
for(int i=0; i < [self.itemsToDisplay count]; i++){
    if (!runThread) {
        return;
    }
    pr = (CGFloat)i/(CGFloat)[self.itemsToDisplay count]; 
    [self performSelectorOnMainThread:@selector(updateProgressBar:)
                           withObject: [NSNumber numberWithFloat:pr]
                        waitUntilDone: YES];
    progressView.progress += 0.5;.............

and nothing at all....