In my app I init a new object, where there is method which calls NSURLConnection's sendAsynchronousRequest method. After the request, I would like to call a method in the caller UIViewController. I tried to use a static method but I then I can't control IBOutlets. How can I do this?
I have tried the following:
// First test    
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    if(data.length > 0)
    {
        NSString *responseBody = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        self.result = responseBody;
        PhotoViewController *photo = [[PhotoViewController alloc] init];
        [photo finishedPost:self]; // Doesnt work
    }
}];
// Second test
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    if(data.length > 0)
    {
        NSString *responseBody = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        self.result = responseBody;
        [PhotoViewController finishedPost:self]; // Doesnt work
    }
}];
				
                        
You'll have to 'remember' which
UIViewControllercalls the object. This can be done for instance with a property.in .h
@property (nonatomic) UIViewController *viewController;in your .m file
@synthesize viewController;Before calling the method, set the property with
Then, you'll be able to call
inside the completion handler of the
sendAsynchronousRequest:method.