Skip to content

Commit

Permalink
DTActionSheet & DTAlertView: Changed designated initializer back to i…
Browse files Browse the repository at this point in the history
…nit so all initializers work correctly on iOS 8, iOS 7 and iOS 6.

Also updated examples a little.
  • Loading branch information
rsanchezsaez committed Jul 23, 2014
1 parent de3b26b commit b4d5d99
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
24 changes: 19 additions & 5 deletions Core/Source/iOS/BlocksAdditions/DTActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,31 @@ @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
{
return [self initWithTitle:title delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
}

// designated initializer
- (id)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)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;
Expand All @@ -59,9 +68,14 @@ - (id)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)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;
}

Expand Down
22 changes: 16 additions & 6 deletions Core/Source/iOS/BlocksAdditions/DTAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,31 @@ - (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
{
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;
Expand All @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions Demo/DTProgressHUDDemo/Source/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 :-(");
Expand Down

0 comments on commit b4d5d99

Please sign in to comment.