Run SelectorInBackground, notify another viewcontroller when it's done

I have a method used to save an image when the user clicks the "Save" button. I use the performSelectorInBackground function to save the image, the view manager opens and the previous view manager is displayed.

I want the table (on the previous UIViewController) to reload its data when image processing is in progress.

How can i do this?

The save method is called as follows:

[self performSelectorInBackground:@selector(saveImage) withObject:nil];
[self.navigationController popViewControllerAnimated:YES];
+5
source share
3 answers

saveImage . - :

// post notification
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ImageSaved" object:nil];

, ,

- (void) imageSaved:(NSNotification *)notification{

    [self.tableView reloadData];

}

viewDidLoad :

[[NSNotificationCenter defaultCenter] addObserver:self
                                selector:@selector(imageSaved:)
                                                 name:@"ImageSaved" object:nil];

, dealloc,

[[NSNotificationCenter defaultCenter] removeObserver:self];
+9

, - saveImage. , -

[self performSelectorInBackground:@selector(saveImage) withObject:previousView];

saveImage, , .

@protocol processingFinishedDelegate
-(void)processingFinished;
@end

, saveImage :

[(id<processingFinishedDelegate>)object processingFinished];

, , previousView .

+2

I am having problems with this to update the UITextView with the proposed “unforgiven” approach. I tried a couple of different ways, but everything failed ... I also tried notifications + observers with this, but did not have time ... Why? It works fine on UILabel, but without a UITextView with this message:

I tried to get a web lock from a stream other than the main stream or web stream. This may be the result of calling UIKit from the secondary stream. Crash now ...

0
source

All Articles