diff --git a/Core/Source/iOS/BlocksAdditions/DTActionSheet.m b/Core/Source/iOS/BlocksAdditions/DTActionSheet.m index ac7199a7..d06335c8 100644 --- a/Core/Source/iOS/BlocksAdditions/DTActionSheet.m +++ b/Core/Source/iOS/BlocksAdditions/DTActionSheet.m @@ -33,9 +33,17 @@ @implementation DTActionSheet BOOL _isDeallocating; } +// designated initializer - (id)init { - return [self initWithTitle:nil]; + self = [super init]; + if (self) + { + _actionsPerIndex = [[NSMutableDictionary alloc] init]; + self.delegate = self; + + } + return self; } - (id)initWithTitle:(NSString *)title @@ -43,12 +51,13 @@ - (id)initWithTitle:(NSString *)title return [self initWithTitle:title delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; } -// designated initializer - (id)initWithTitle:(NSString *)title delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... { - self = [super initWithTitle:title delegate:nil cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:nil]; + self = [self init]; if (self) { + self.title = title; + if (otherButtonTitles != nil) { [self addButtonWithTitle:otherButtonTitles]; va_list args; @@ -59,9 +68,14 @@ - (id)initWithTitle:(NSString *)title delegate:(id)delega } va_end(args); } + + if (destructiveButtonTitle) { + [self addDestructiveButtonWithTitle:destructiveButtonTitle block:nil]; + } + if (cancelButtonTitle) { + [self addCancelButtonWithTitle:cancelButtonTitle block:nil]; + } - _actionsPerIndex = [[NSMutableDictionary alloc] init]; - self.delegate = self; _externalDelegate = delegate; } diff --git a/Core/Source/iOS/BlocksAdditions/DTAlertView.m b/Core/Source/iOS/BlocksAdditions/DTAlertView.m index 4665d135..8097bfdc 100644 --- a/Core/Source/iOS/BlocksAdditions/DTAlertView.m +++ b/Core/Source/iOS/BlocksAdditions/DTAlertView.m @@ -31,9 +31,16 @@ - (void)dealloc _isDeallocating = YES; } +// designated initializer - (id)init { - return [self initWithTitle:nil message:nil]; + self = [super init]; + if (self) + { + _actionsPerIndex = [[NSMutableDictionary alloc] init]; + self.delegate = self; + } + return self; } - (id)initWithTitle:(NSString *)title message:(NSString *)message @@ -41,12 +48,14 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message return [self initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; } -// designated initializer - (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... { - self = [super initWithTitle:title message:message delegate:nil cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil]; + self = [self init]; if (self) { + self.title = title; + self.message = message; + if (otherButtonTitles != nil) { [self addButtonWithTitle:otherButtonTitles]; va_list args; @@ -57,9 +66,10 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)d } va_end(args); } - - _actionsPerIndex = [[NSMutableDictionary alloc] init]; - self.delegate = self; + if (cancelButtonTitle) { + [self addCancelButtonWithTitle:cancelButtonTitle block:nil]; + } + _externalDelegate = delegate; } return self; diff --git a/Demo/DTProgressHUDDemo/Source/ViewController.m b/Demo/DTProgressHUDDemo/Source/ViewController.m index 868e556e..2107b52c 100644 --- a/Demo/DTProgressHUDDemo/Source/ViewController.m +++ b/Demo/DTProgressHUDDemo/Source/ViewController.m @@ -98,37 +98,34 @@ - (IBAction)hidePressed:(id)sender - (IBAction)showDTActionSheet:(id)sender { -// DTActionSheet *actionSheet = [[DTActionSheet alloc] initWithTitle:@"This is a block-based DTActionSheet"]; DTActionSheet *actionSheet = [[DTActionSheet alloc] initWithTitle:@"This is a block-based DTActionSheet" delegate:nil cancelButtonTitle:nil - destructiveButtonTitle:nil + destructiveButtonTitle:@"Destructive" otherButtonTitles:@"a", @"b", nil]; - [actionSheet addDestructiveButtonWithTitle:@"Say hi" block:^ + [actionSheet addButtonWithTitle:@"Say hi" block:^ { NSLog(@"Hi!"); }]; - [actionSheet addCancelButtonWithTitle:@"Cancel" block:^ { NSLog(@"Cancelled :-("); }]; [actionSheet showInView:self.view]; - } - (IBAction)showDTAlertViewidsender:(id)sender { DTAlertView *alertView = [[DTAlertView alloc] initWithTitle:@"DTAlertView" message:@"This is a block-based DTAlertView" delegate:nil - cancelButtonTitle:nil otherButtonTitles:@"a", @"b", nil]; + cancelButtonTitle:nil + otherButtonTitles:@"a", @"b", nil]; [alertView addButtonWithTitle:@"Say hi" block:^ { NSLog(@"Hi!"); }]; - [alertView addCancelButtonWithTitle:@"Cancel" block:^ { NSLog(@"Cancelled :-(");