8

This is the code I have:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {


    [picker dismissViewControllerAnimated:YES completion:^(void){
        NSLog(@"Test");

    }];
}

It dismisses the modal view controller, but doesn't call the completion argument. Am i doing something wrong?

1 Answer 1

16

void completion handlers are filled with a simple ^{, I've never seen your syntax before....

[picker dismissViewControllerAnimated:YES completion:^{
        NSLog(@"Test");

    }];

The only possible explanation I can come up with is that your image picker is being dismissed by some other means, and that you are not it's delegate (therefore you would not receive the didFinishPickingMediaWithInfo message). Another possibility could be a failure within the SDK at the time. I know from running a quick example project, that the completion block fires as expected in both syntactical models.

5
  • I actually put void in because it wasn't working as you posted above. I changed it back, and it still doesn't work.
    – Andrew
    Apr 15, 2012 at 17:10
  • Are you using the right side of the log then? the farthest right button should be selected.
    – CodaFi
    Apr 15, 2012 at 17:32
  • 1
    This syntax and the syntax in the question are equivalent. Any of ^void (void){ NSLog(@"Test"); }, ^(void){ NSLog(@"Test"); }, or ^{ NSLog(@"Test"); } will become exactly the same Block. IOW, void is assumed for a Block's return type and parameter list when nothing is specified.
    – jscs
    Apr 15, 2012 at 19:40
  • Well jeez. Looking back, I really should delete this... but I can't. I have no possible explanation for why the completion block wouldn't fire, other than a jankyness with the new API.
    – CodaFi
    Sep 19, 2012 at 3:10
  • 1
    I can confirm that if the view controller you are trying to dismiss in the method has already been dismissed, the completion block does not execute.
    – Drew C
    Nov 10, 2015 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.