I am having a bit of trouble with displaying the progress of a longer mainthread action (needs to be in the main thread).
The action is called by pressing a button.
-(void)getCSVExport:(id)sender{
...
NSString *filePath = [path stringByAppendingPathComponent:fileName];
NSData *csvData = [NSData dataWithContentsOfFile:filePath];
if (nil == csvData) {
_progressView.hidden = NO;
[self.view bringSubviewToFront:_progressView];
_progressView.progress = 0;
csvData = [self generateCSVExportForMonth:_monthToExportInt];
[csvData writeToFile:filePath atomically:YES];
_progressView.hidden = YES;
}
...
}
within the funktion generateCSVExportForMonth:
i am updating the progress with _progressView.progress = newValue
.
i now have 2 problems:
1) when pressing the button that calls getCSVExport:
the button remains highlighted until the call is finished.
2) the progressView does never show up, let alone update itself.
information: the call takes between .5 and 2 seconds depending on the device.
any ideas where i've gone wrong?
// EDIT: new version with backgroundThread:
[self.view bringSubviewToFront:_progressView];
_progressView.progress = 0;
[self performSelector:@selector(assignCSVData:) onThread:[NSThread new] withObject:csvData waitUntilDone:YES];
_progressView.hidden = YES;
and the time expensive call:
-(void)assignCSVData:(NSData*)data{
data = [self generateCSVExportForMonth:_monthToExportInt];
}
this results in a deadlock upon the performSelector
call.