UIAlertView用block方式代替delegate(二)

2014-11-24 07:25:39 · 作者: · 浏览: 2
if (completionHandler != nil) { completionHandler(alertView, buttonIndex); } } #pragma mark - Utility methods /* * Utility selector to show an alert with a title, a message and a button to dimiss. */ + (void)showWithTitle:(NSString *)title message:(NSString *)message handler:(UIAlertViewHandler)handler { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert showWithHandler:handler]; } /* * Utility selector to show an alert with an "Error" title, a message and a button to dimiss. */ + (void)showErrorWithMessage:(NSString *)message handler:(UIAlertViewHandler)handler { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert showWithHandler:handler]; } /* * Utility selector to show an alert with a "Warning" title, a message and a button to dimiss. */ + (void)showWarningWithMessage:(NSString *)message handler:(UIAlertViewHandler)handler { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert showWithHandler:handler]; } /* * Utility selector to show a confirmation dialog with a title, a message and two buttons to accept or cancel. */ + (void)showConfirmationDialogWithTitle:(NSString *)title message:(NSString *)message handler:(UIAlertViewHandler)handler { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; [alert showWithHandler:handler]; } @end