mirror of
https://github.com/samsonjs/Marshmallows.git
synced 2026-03-25 09:05:52 +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
|
||||
//
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue