ryanmaxwell / UIAlertView-Blocks

Category on UIAlertView to use inline block callbacks instead of delegate callbacks.
MIT License
425 stars 58 forks source link

cancelBlock is never called #1

Closed shmidt closed 10 years ago

shmidt commented 10 years ago

Hi,

I tried your code in test sample and see that cancelBlock is never called.

ryanmaxwell commented 10 years ago

Hi - the 'cancelBlock' is called in the same situations as the UIAlertViewDelegate - (void)alertViewCancel:(UIAlertView *)alertView method. In Apple's documentation:

An alert view can be canceled at any time by the system—for example, when the user taps the Home button. The alertView:willDismissWithButtonIndex: and alertView:didDismissWithButtonIndex: methods are invoked after this method.

I know it's a little confusing - if you wanted to do something on the user tapping the cancel button, the check would occur in the tap block, e.g.

av.tapBlock = ^(UIAlertView *alertView, NSInteger buttonIndex) {
        if (buttonIndex == alertView.cancelButtonIndex) {
            NSLog(@"Cancel button tapped.");
        } else {
            ...
        }
    };

I've updated the example project to use this example.

shmidt commented 10 years ago

Thank you :+1: