Here is the problem.
I have a method called -(void)searchingInBackground which is running in background (performSelectorInBackground).
In this method, I have couple of different threads which are running in background too (performSelectorInBackground). Like this:
-(void)searchingInBackground { @autoreleasepool { [self performSelectorInBackground:@selector(getDuplicatedPictures:) withObject:copyArray]; } @autoreleasepool { [self performSelectorInBackground:@selector(getLocationsOfPhotos:) withObject:copyArray]; } ... (and so on) }
In each of functions in threads (ie. getDuplicatedPictures, getLocationsOfPhotos...) they will generate NSStrings at the end and I will use those strings to update my text field GUI.
In order to update my text field GUI. I created a function called UpdateGUI which will use to help me update all of my NSStrings. Like this,
-(void)UpdateUI { [_NumDupPhotosLabel(label for GUI) setStringValue: resultDupPhotos(string from thread function which is getDuplicatedPictures in this case)]; ....(includes all of my strings from threads) }
Here is the problem, when I call this UpdateGUI using performSelectorOnMainThread in each of threads function. It will give me EXC_BAD_ACCESS. Here is what I did. For example:
-(void)getDupicatedPictures { resultDupPhotos = .....; [self performSelectorOnMainThread:@selector(UpdateUI) withObject:nil waitUntilDone:YES]; }
If I do not use performSelectorOnMainThread, just set the values directly in those functions it works fine. I just want to better organize the code.
-(void)getDuplicatedPictures { resultDupPhotos = .....; [_NumDupPhotosLabel setStringValue: resultDupPhotos]; (works good and it will set the value to the GUI label) }
Could you guys tell me how to fix this? Thanks!!!