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

This commit is contained in:
Sami Samhuri 2012-11-14 22:08:32 -08:00
parent 348909fc04
commit a1e5adf606
4 changed files with 25 additions and 9 deletions

View file

@ -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 file

@ -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"
@ -21,12 +21,21 @@
}
+ (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 file

@ -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 file

@ -26,8 +26,8 @@
- (void) alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
BOOL ok = (buttonIndex == 1);
_callback(ok);
BOOL canceled = (buttonIndex == 0);
_callback(buttonIndex, canceled);
}
- (void) dealloc