Permalink
Browse files

add an alert view shortcut that accepts OK & cancel button titles

  • Loading branch information...
1 parent 348909f commit a1e5adf606cf0b2e760f473a992b1b24bda9d6bb @samsonjs committed Nov 15, 2012
View
11 Marshmallows/UIAlertView+marshmallows.h
@@ -3,15 +3,20 @@
// DatingX
//
// Created by Sami Samhuri on 11-08-24.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
+// Copyright 2011 Guru Logic. All rights reserved.
//
#import <UIKit/UIKit.h>
-
-typedef void (^UIAlertViewCallback)(BOOL ok);
+#import "UIAlertViewDelegate.h"
@interface UIAlertView (UIAlertView_marshmallows)
+ (void) showAlertWithTitle: (NSString *)title message: (NSString *)message;
++ (void) confirmWithTitle: (NSString *)title message: (NSString *)message then: (UIAlertViewCallback)callback;
++ (void) confirmWithTitle: (NSString *)title
+ message: (NSString *)message
+ cancelTitle: (NSString *)cancelTitle
+ okTitle: (NSString *)okTitle
+ then: (UIAlertViewCallback)callback;
@end
View
15 Marshmallows/UIAlertView+marshmallows.m
@@ -3,7 +3,7 @@
// DatingX
//
// Created by Sami Samhuri on 11-08-24.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
+// Copyright 2011 Guru Logic. All rights reserved.
//
#import "UIAlertView+marshmallows.h"
@@ -22,11 +22,20 @@ + (void) showAlertWithTitle: (NSString *)title message: (NSString *)message
+ (void) confirmWithTitle: (NSString *)title message: (NSString *)message then: (UIAlertViewCallback)callback
{
+ [self confirmWithTitle: title message: message cancelTitle: @"Cancel" okTitle: @"OK" then: callback];
+}
+
++ (void) confirmWithTitle: (NSString *)title
+ message: (NSString *)message
+ cancelTitle: (NSString *)cancelTitle
+ okTitle: (NSString *)okTitle
+ then: (UIAlertViewCallback)callback
+{
[[[[self alloc] initWithTitle: title
message: message
delegate: [UIAlertViewDelegate alertViewDelegateWithCallback: callback]
- cancelButtonTitle: @"Cancel"
- otherButtonTitles: @"OK", nil] autorelease] show];
+ cancelButtonTitle: cancelTitle
+ otherButtonTitles: okTitle, nil] autorelease] show];
}
@end
View
4 Marshmallows/UIAlertViewDelegate.h
@@ -7,7 +7,9 @@
//
#import <Foundation/Foundation.h>
-#import "UIAlertView+marshmallows.h"
+#import <UIKit/UIKit.h>
+
+typedef void (^UIAlertViewCallback)(int buttonClicked, BOOL canceled);
@interface UIAlertViewDelegate : NSObject <UIAlertViewDelegate>
{
View
4 Marshmallows/UIAlertViewDelegate.m
@@ -26,8 +26,8 @@ - (id) initWithCallback: (UIAlertViewCallback)callback
- (void) alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
- BOOL ok = (buttonIndex == 1);
- _callback(ok);
+ BOOL canceled = (buttonIndex == 0);
+ _callback(buttonIndex, canceled);
}
- (void) dealloc

0 comments on commit a1e5adf

Please sign in to comment.