Skip to content
Browse files

UIAlertView (Block) returns [alert autorelease] – useful when need to…

… recognize UIViewAlert later.
  • Loading branch information...
1 parent 2efa37a commit 3b888adeff9208844f422af6d4e92011449acb64 @SlavaBushtruk SlavaBushtruk committed Mar 26, 2011
Showing with 27 additions and 28 deletions.
  1. +11 −11 MKAdditions/UIAlertView+MKBlockAdditions.h
  2. +16 −17 MKAdditions/UIAlertView+MKBlockAdditions.m
View
22 MKAdditions/UIAlertView+MKBlockAdditions.h
@@ -13,18 +13,18 @@
}
-+ (void) alertViewWithTitle:(NSString*) title
- message:(NSString*) message;
++ (UIAlertView*) alertViewWithTitle:(NSString*) title
+ message:(NSString*) message;
-+ (void) alertViewWithTitle:(NSString*) title
- message:(NSString*) message
- cancelButtonTitle:(NSString*) cancelButtonTitle;
++ (UIAlertView*) alertViewWithTitle:(NSString*) title
+ message:(NSString*) message
+ cancelButtonTitle:(NSString*) cancelButtonTitle;
-+ (void) alertViewWithTitle:(NSString*) title
- message:(NSString*) message
- cancelButtonTitle:(NSString*) cancelButtonTitle
- otherButtonTitles:(NSArray*) otherButtons
- onDismiss:(DismissBlock) dismissed
- onCancel:(CancelBlock) cancelled;
++ (UIAlertView*) alertViewWithTitle:(NSString*) title
+ message:(NSString*) message
+ cancelButtonTitle:(NSString*) cancelButtonTitle
+ otherButtonTitles:(NSArray*) otherButtons
+ onDismiss:(DismissBlock) dismissed
+ onCancel:(CancelBlock) cancelled;
@end
View
33 MKAdditions/UIAlertView+MKBlockAdditions.m
@@ -13,13 +13,12 @@
@implementation UIAlertView (Block)
-+ (void) alertViewWithTitle:(NSString*) title
++ (UIAlertView*) alertViewWithTitle:(NSString*) title
message:(NSString*) message
cancelButtonTitle:(NSString*) cancelButtonTitle
otherButtonTitles:(NSArray*) otherButtons
onDismiss:(DismissBlock) dismissed
- onCancel:(CancelBlock) cancelled
-{
+ onCancel:(CancelBlock) cancelled {
[_cancelBlock release];
_cancelBlock = [cancelled copy];
@@ -37,33 +36,32 @@ + (void) alertViewWithTitle:(NSString*) title
[alert addButtonWithTitle:buttonTitle];
[alert show];
- [alert release];
+ return [alert autorelease];
}
-+ (void) alertViewWithTitle:(NSString*) title
- message:(NSString*) message
-{
- [UIAlertView alertViewWithTitle:title
- message:message
- cancelButtonTitle:NSLocalizedString(@"Dismiss", @"")];
++ (UIAlertView*) alertViewWithTitle:(NSString*) title
+ message:(NSString*) message {
+
+ return [UIAlertView alertViewWithTitle:title
+ message:message
+ cancelButtonTitle:NSLocalizedString(@"Dismiss", @"")];
}
-+ (void) alertViewWithTitle:(NSString*) title
++ (UIAlertView*) alertViewWithTitle:(NSString*) title
message:(NSString*) message
- cancelButtonTitle:(NSString*) cancelButtonTitle
-{
+ cancelButtonTitle:(NSString*) cancelButtonTitle {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:cancelButtonTitle
otherButtonTitles: nil];
[alert show];
- [alert release];
+ return [alert autorelease];
}
-+ (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger) buttonIndex
-{
++ (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger) buttonIndex {
+
if(buttonIndex == [alertView cancelButtonIndex])
{
_cancelBlock();
@@ -73,4 +71,5 @@ + (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger)
_dismissBlock(buttonIndex - 1); // cancel button is button 0
}
}
-@end
+
+@end

0 comments on commit 3b888ad

Please sign in to comment.
Something went wrong with that request. Please try again.