mirror of
https://github.com/samsonjs/Marshmallows.git
synced 2026-04-27 15:07:42 +00:00
add an alert view shortcut that accepts OK & cancel button titles
This commit is contained in:
parent
348909fc04
commit
a1e5adf606
4 changed files with 25 additions and 9 deletions
|
|
@ -3,15 +3,20 @@
|
||||||
// DatingX
|
// DatingX
|
||||||
//
|
//
|
||||||
// Created by Sami Samhuri on 11-08-24.
|
// 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>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "UIAlertViewDelegate.h"
|
||||||
typedef void (^UIAlertViewCallback)(BOOL ok);
|
|
||||||
|
|
||||||
@interface UIAlertView (UIAlertView_marshmallows)
|
@interface UIAlertView (UIAlertView_marshmallows)
|
||||||
|
|
||||||
+ (void) showAlertWithTitle: (NSString *)title message: (NSString *)message;
|
+ (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
|
@end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// DatingX
|
// DatingX
|
||||||
//
|
//
|
||||||
// Created by Sami Samhuri on 11-08-24.
|
// 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"
|
#import "UIAlertView+marshmallows.h"
|
||||||
|
|
@ -21,12 +21,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) confirmWithTitle: (NSString *)title message: (NSString *)message then: (UIAlertViewCallback)callback
|
+ (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
|
[[[[self alloc] initWithTitle: title
|
||||||
message: message
|
message: message
|
||||||
delegate: [UIAlertViewDelegate alertViewDelegateWithCallback: callback]
|
delegate: [UIAlertViewDelegate alertViewDelegateWithCallback: callback]
|
||||||
cancelButtonTitle: @"Cancel"
|
cancelButtonTitle: cancelTitle
|
||||||
otherButtonTitles: @"OK", nil] autorelease] show];
|
otherButtonTitles: okTitle, nil] autorelease] show];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "UIAlertView+marshmallows.h"
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
typedef void (^UIAlertViewCallback)(int buttonClicked, BOOL canceled);
|
||||||
|
|
||||||
@interface UIAlertViewDelegate : NSObject <UIAlertViewDelegate>
|
@interface UIAlertViewDelegate : NSObject <UIAlertViewDelegate>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
- (void) alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
|
- (void) alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
|
||||||
{
|
{
|
||||||
BOOL ok = (buttonIndex == 1);
|
BOOL canceled = (buttonIndex == 0);
|
||||||
_callback(ok);
|
_callback(buttonIndex, canceled);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue