performSelectorInBackground, notify other viewcontroller when done
iphone, multithreading
Solution
In your `saveImage` method, post a notification just after finishing saving the image and before returning from the method. Something like this:
// post notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"ImageSaved" object:nil];
In the controller handling the table, implement
- (void) imageSaved:(NSNotification *)notification{
[self.tableView reloadData];
}
and in its `viewDidLoad` method add the following code to register for notifications:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(imageSaved:)
name:@"ImageSaved" object:nil];
finally, unregister in the `dealloc` method adding
[[NSNotificationCenter defaultCenter] removeObserver:self];
Problem
I have a method used to save an image when the user clicks Save. I use performSelectorInBackground to save the image, the viewcontroller is popped and the previous viewcontroller is shown. I want the table (on the previousUIViewController) to reload its data when the imagesaving is done. How can I do this? The save method is called like this: ``` [self performSelectorInBackground:@selector(saveImage) withObject:nil]; [self.navigationController popViewControllerAnimated:YES]; ```