From 161f7612572fa92a4b6d0af0abdf3390187c3e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 16:35:44 +0100 Subject: [PATCH 1/9] DTAlertView: Moved action block to delegate clickedButtonAtIndex: method --- Core/Source/iOS/BlocksAdditions/DTAlertView.m | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Core/Source/iOS/BlocksAdditions/DTAlertView.m b/Core/Source/iOS/BlocksAdditions/DTAlertView.m index c04d5061..7e37a93e 100644 --- a/Core/Source/iOS/BlocksAdditions/DTAlertView.m +++ b/Core/Source/iOS/BlocksAdditions/DTAlertView.m @@ -85,6 +85,14 @@ - (void)setCancelBlock:(DTAlertViewBlock)block - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { + NSNumber *key = [NSNumber numberWithInteger:buttonIndex]; + + DTAlertViewBlock block = [_actionsPerIndex objectForKey:key]; + if (block) + { + block(); + } + if ([_externalDelegate respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) { [_externalDelegate alertView:self clickedButtonAtIndex:buttonIndex]; @@ -130,15 +138,6 @@ - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { - NSNumber *key = [NSNumber numberWithInteger:buttonIndex]; - - DTAlertViewBlock block = [_actionsPerIndex objectForKey:key]; - - if (block) - { - block(); - } - if ([_externalDelegate respondsToSelector:@selector(alertView:didDismissWithButtonIndex:)]) { [_externalDelegate alertView:self didDismissWithButtonIndex:buttonIndex]; From 40e3d609fbcc409270dee023a654d0ce52198111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 16:36:03 +0100 Subject: [PATCH 2/9] DTProgressHUDDemo: Added DTAlertView example --- .../Base.lproj/Main_iPhone.storyboard | 47 +++++++++++++------ .../DTProgressHUDDemo/Source/ViewController.m | 17 +++++++ 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Demo/DTProgressHUDDemo/Resources/Base.lproj/Main_iPhone.storyboard b/Demo/DTProgressHUDDemo/Resources/Base.lproj/Main_iPhone.storyboard index 7e4bf69f..d9fa42cf 100644 --- a/Demo/DTProgressHUDDemo/Resources/Base.lproj/Main_iPhone.storyboard +++ b/Demo/DTProgressHUDDemo/Resources/Base.lproj/Main_iPhone.storyboard @@ -72,21 +72,6 @@ - + + @@ -139,6 +154,7 @@ + @@ -149,6 +165,7 @@ + diff --git a/Demo/DTProgressHUDDemo/Source/ViewController.m b/Demo/DTProgressHUDDemo/Source/ViewController.m index 77b07fee..d7f97c55 100644 --- a/Demo/DTProgressHUDDemo/Source/ViewController.m +++ b/Demo/DTProgressHUDDemo/Source/ViewController.m @@ -10,6 +10,7 @@ #import "DTProgressHUD.h" #import "DTActionSheet.h" +#import "DTAlertView.h" @interface ViewController () @@ -116,6 +117,22 @@ - (IBAction)showDTActionSheet:(id)sender } +- (IBAction)showDTAlertViewidsender:(id)sender { + DTAlertView *alertView = [[DTAlertView alloc] initWithTitle:@"DTAlertView" + message:@"This is a block-based DTAlertView"]; + + [alertView addButtonWithTitle:@"Say hi" block:^ + { + NSLog(@"Hi!"); + }]; + + [alertView addCancelButtonWithTitle:@"Cancel" block:^ + { + NSLog(@"Cancelled :-("); + }]; + [alertView show]; +} + - (void)_createProgressHUD { _progressHUD = [[DTProgressHUD alloc] init]; From 493628c65f857e63304f2cb4ad434b0dfe961782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 19:37:04 +0100 Subject: [PATCH 3/9] DTAlertView: Remove duplicated init method Only one designated initializer should exist per class. --- Core/Source/iOS/BlocksAdditions/DTAlertView.m | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Core/Source/iOS/BlocksAdditions/DTAlertView.m b/Core/Source/iOS/BlocksAdditions/DTAlertView.m index 7e37a93e..9c989d85 100644 --- a/Core/Source/iOS/BlocksAdditions/DTAlertView.m +++ b/Core/Source/iOS/BlocksAdditions/DTAlertView.m @@ -26,18 +26,6 @@ @implementation DTAlertView // overwrite standard initializer so that we can set our own delegate -- (id)init -{ - self = [super init]; - if (self) - { - _actionsPerIndex = [[NSMutableDictionary alloc] init]; - self.delegate = self; - } - - return self; -} - - (void)dealloc { _isDeallocating = YES; From d24ccb3a4afc90eef8f3d62f7c29651c19f50511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 20:25:16 +0100 Subject: [PATCH 4/9] DTActionSheet: Fixed to work on iOS 8 --- .../iOS/BlocksAdditions/DTActionSheet.m | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Core/Source/iOS/BlocksAdditions/DTActionSheet.m b/Core/Source/iOS/BlocksAdditions/DTActionSheet.m index 1930925c..ac7199a7 100644 --- a/Core/Source/iOS/BlocksAdditions/DTActionSheet.m +++ b/Core/Source/iOS/BlocksAdditions/DTActionSheet.m @@ -33,25 +33,36 @@ @implementation DTActionSheet BOOL _isDeallocating; } -- (id)init +- (id)init { - self = [super init]; - if (self) - { - _actionsPerIndex = [[NSMutableDictionary alloc] init]; - self.delegate = self; - } - - return self; + return [self initWithTitle:nil]; } -// designated initializer - (id)initWithTitle:(NSString *)title { - self = [self init]; + 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]; if (self) { - self.title = title; + if (otherButtonTitles != nil) { + [self addButtonWithTitle:otherButtonTitles]; + va_list args; + va_start(args, otherButtonTitles); + NSString *title = nil; + while( (title = va_arg(args, NSString *)) ) { + [self addButtonWithTitle:title]; + } + va_end(args); + } + + _actionsPerIndex = [[NSMutableDictionary alloc] init]; + self.delegate = self; + _externalDelegate = delegate; } return self; From 3e42b58e991113f28868a72174f749d242e17698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 20:25:43 +0100 Subject: [PATCH 5/9] DTAlertView: Improved initalizers design so all three initializers work correctly --- Core/Source/iOS/BlocksAdditions/DTAlertView.m | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Core/Source/iOS/BlocksAdditions/DTAlertView.m b/Core/Source/iOS/BlocksAdditions/DTAlertView.m index 9c989d85..4665d135 100644 --- a/Core/Source/iOS/BlocksAdditions/DTAlertView.m +++ b/Core/Source/iOS/BlocksAdditions/DTAlertView.m @@ -31,14 +31,36 @@ - (void)dealloc _isDeallocating = YES; } -// designated initializer +- (id)init +{ + return [self initWithTitle:nil message:nil]; +} + - (id)initWithTitle:(NSString *)title message:(NSString *)message { - self = [super initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; + 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]; if (self) { + if (otherButtonTitles != nil) { + [self addButtonWithTitle:otherButtonTitles]; + va_list args; + va_start(args, otherButtonTitles); + NSString *title = nil; + while( (title = va_arg(args, NSString *)) ) { + [self addButtonWithTitle:title]; + } + va_end(args); + } + _actionsPerIndex = [[NSMutableDictionary alloc] init]; self.delegate = self; + _externalDelegate = delegate; } return self; } From 4b030f2a6cb6f8ad290ad168a8f3fefb57c04f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 20:38:50 +0100 Subject: [PATCH 6/9] DTProgressHUD: Updated DTActionSheet and DTAlertView examples --- Demo/DTProgressHUDDemo/Source/ViewController.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Demo/DTProgressHUDDemo/Source/ViewController.m b/Demo/DTProgressHUDDemo/Source/ViewController.m index d7f97c55..868e556e 100644 --- a/Demo/DTProgressHUDDemo/Source/ViewController.m +++ b/Demo/DTProgressHUDDemo/Source/ViewController.m @@ -98,12 +98,13 @@ - (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 - otherButtonTitles:nil]; - + otherButtonTitles:@"a", @"b", nil]; + [actionSheet addDestructiveButtonWithTitle:@"Say hi" block:^ { NSLog(@"Hi!"); @@ -119,7 +120,9 @@ - (IBAction)showDTActionSheet:(id)sender - (IBAction)showDTAlertViewidsender:(id)sender { DTAlertView *alertView = [[DTAlertView alloc] initWithTitle:@"DTAlertView" - message:@"This is a block-based DTAlertView"]; + message:@"This is a block-based DTAlertView" + delegate:nil + cancelButtonTitle:nil otherButtonTitles:@"a", @"b", nil]; [alertView addButtonWithTitle:@"Say hi" block:^ { From 291c78b3e0f9167c49b3b1e5e23debb85fac897f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 20:39:22 +0100 Subject: [PATCH 7/9] DTAlertView & DTActionSheet: Improved unit tests to cover all three possible initalizers --- Test/Source/DTActionSheetTest.m | 61 +++++++++++++++++++++++++++++++++ Test/Source/DTAlertViewTest.m | 30 +++++++++++++--- 2 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 Test/Source/DTActionSheetTest.m diff --git a/Test/Source/DTActionSheetTest.m b/Test/Source/DTActionSheetTest.m new file mode 100644 index 00000000..de90539e --- /dev/null +++ b/Test/Source/DTActionSheetTest.m @@ -0,0 +1,61 @@ +// +// DTActionSheetTest.m +// DTFoundation +// +// Created by Rene Pirringer on 22.07.14. +// Copyright (c) 2014 Cocoanetics. All rights reserved. +// + +#import +#import +#import "DTActionSheet.h" + + +@interface DTActionSheet(Private) +@end + + +@implementation DTActionSheet(Private) +@end + + +@interface DTActionSheetTest : XCTestCase +@end + + +@implementation DTActionSheetTest + +- (void)testInitMethods { + __block BOOL blockExecuted = NO; + DTActionSheet *actionSheet = [[DTActionSheet alloc] init]; + [actionSheet addButtonWithTitle:@"Ok" block:^{ + blockExecuted = YES; + }]; + + [actionSheet actionSheet:actionSheet clickedButtonAtIndex:actionSheet.numberOfButtons - 1]; + + XCTAssertTrue(blockExecuted, @"The ok button block should be executed"); + + blockExecuted = NO; + actionSheet = [[DTActionSheet alloc] initWithTitle:@"Foo"]; + [actionSheet addButtonWithTitle:@"Ok" block:^{ + blockExecuted = YES; + }]; + + [actionSheet actionSheet:actionSheet clickedButtonAtIndex:actionSheet.numberOfButtons - 1]; + + XCTAssertTrue(blockExecuted, @"The ok button block should be executed"); + + blockExecuted = NO; + actionSheet = [[DTActionSheet alloc] initWithTitle:@"Foo" delegate:nil cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"a", @"b", nil]; + [actionSheet addButtonWithTitle:@"Ok" block:^{ + blockExecuted = YES; + }]; + + [actionSheet actionSheet:actionSheet clickedButtonAtIndex:actionSheet.numberOfButtons - 1]; + + XCTAssertTrue(blockExecuted, @"The ok button block should be executed"); +} + + +@end diff --git a/Test/Source/DTAlertViewTest.m b/Test/Source/DTAlertViewTest.m index 893b39d6..98565f93 100644 --- a/Test/Source/DTAlertViewTest.m +++ b/Test/Source/DTAlertViewTest.m @@ -17,23 +17,43 @@ @interface DTAlertView(Private) @implementation DTAlertView(Private) @end -@interface DTAlertViewTest : XCTestCase +@interface DTAlertViewTest : XCTestCase @end -@implementation DTAlertViewTest +@implementation DTAlertViewTest -- (void)testInitWithTitle { +- (void)testInitMethods { __block BOOL blockExecuted = NO; - DTAlertView *alertView = [[DTAlertView alloc] initWithTitle:@"Foo" message:@"bar"]; + DTAlertView *alertView = [[DTAlertView alloc] init]; [alertView addButtonWithTitle:@"Ok" block:^{ blockExecuted = YES; }]; - [alertView alertView:alertView didDismissWithButtonIndex:0]; + [alertView alertView:alertView clickedButtonAtIndex:alertView.numberOfButtons - 1]; XCTAssertTrue(blockExecuted, @"The ok button block should be executed"); + + blockExecuted = NO; + alertView = [[DTAlertView alloc] initWithTitle:@"Foo" message:@"bar"]; + [alertView addButtonWithTitle:@"Ok" block:^{ + blockExecuted = YES; + }]; + + [alertView alertView:alertView clickedButtonAtIndex:alertView.numberOfButtons - 1]; + + XCTAssertTrue(blockExecuted, @"The ok button block should be executed"); + + blockExecuted = NO; + alertView = [[DTAlertView alloc] initWithTitle:@"Foo" message:@"bar" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"a", @"b", nil]; + [alertView addButtonWithTitle:@"Ok" block:^{ + blockExecuted = YES; + }]; + + [alertView alertView:alertView clickedButtonAtIndex:alertView.numberOfButtons - 1]; + + XCTAssertTrue(blockExecuted, @"The ok button block should be executed"); } From de3b26b2134ced35c11f3b057e32bed73cf3817a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 20:40:29 +0100 Subject: [PATCH 8/9] Project: Added DTActionSheet unit test --- DTFoundation.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DTFoundation.xcodeproj/project.pbxproj b/DTFoundation.xcodeproj/project.pbxproj index 64cdb00a..ea7d5202 100644 --- a/DTFoundation.xcodeproj/project.pbxproj +++ b/DTFoundation.xcodeproj/project.pbxproj @@ -332,6 +332,7 @@ A7FB1219175C9D5000D4B7F0 /* DTWeakSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */; settings = {ATTRIBUTES = (Public, ); }; }; A7FB121A175C9D5000D4B7F0 /* DTWeakSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */; }; A7FB121B175C9D5000D4B7F0 /* DTWeakSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */; }; + BC4D93C1198044CC00961495 /* DTActionSheetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = BC4D93C0198044C800961495 /* DTActionSheetTest.m */; }; C0494033163C863A470098D8 /* DTZipArchiveNode.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C0494CD06FFAB6AEAC8ADAD4 /* DTZipArchiveNode.h */; }; C04941BC829C1022DF240F4C /* DTZipArchiveNode.m in Sources */ = {isa = PBXBuildFile; fileRef = C0494FCC2C675F2CDF315027 /* DTZipArchiveNode.m */; }; C049420F39CD4294FCE0F549 /* DTZipArchiveGZip.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C04943358446F1A9BA86F458 /* DTZipArchiveGZip.h */; }; @@ -827,6 +828,7 @@ A7FAA3871652291D006ED151 /* NSURL+DTComparing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+DTComparing.h"; sourceTree = ""; }; A7FAA3881652291D006ED151 /* NSURL+DTComparing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+DTComparing.m"; sourceTree = ""; }; A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTWeakSupport.h; sourceTree = ""; }; + BC4D93C0198044C800961495 /* DTActionSheetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTActionSheetTest.m; sourceTree = ""; }; C0494136CFE5018E95613EA7 /* gzip_sample.txt.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = gzip_sample.txt.gz; sourceTree = ""; }; C04942C8BD89694FA3602A10 /* gzip_sample.txt.original */ = {isa = PBXFileReference; lastKnownFileType = file.original; path = gzip_sample.txt.original; sourceTree = ""; }; C04943358446F1A9BA86F458 /* DTZipArchiveGZip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTZipArchiveGZip.h; sourceTree = ""; }; @@ -1589,6 +1591,7 @@ A7D60FE515D3B15300AEDD1B /* Source */ = { isa = PBXGroup; children = ( + BC4D93C0198044C800961495 /* DTActionSheetTest.m */, A7640E4016F3226B003A7B43 /* DTASN1 */, A768BE4217FC40E6008834C6 /* DTBlockFunctionsTest.h */, A768BE4317FC40E6008834C6 /* DTBlockFunctionsTest.m */, @@ -2736,6 +2739,7 @@ files = ( A705E8A2197ED5D2001B16A7 /* DTLogTest.m in Sources */, A7917C8E191A31A300964D63 /* DTScriptingTest.m in Sources */, + BC4D93C1198044CC00961495 /* DTActionSheetTest.m in Sources */, A7917C8F191A31A300964D63 /* NSArrayDTErrorTest.m in Sources */, A7917C91191A31A300964D63 /* DTZipArchiveTest.m in Sources */, A7917C8A191A31A300964D63 /* DTASN1SerializationTest.m in Sources */, From b4d5d99a3db07828bd625d8cec02248da8882cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sa=CC=81nchez-Sa=CC=81ez?= Date: Wed, 23 Jul 2014 21:42:12 +0100 Subject: [PATCH 9/9] DTActionSheet & DTAlertView: Changed designated initializer back to init so all initializers work correctly on iOS 8, iOS 7 and iOS 6. Also updated examples a little. --- .../iOS/BlocksAdditions/DTActionSheet.m | 24 +++++++++++++++---- Core/Source/iOS/BlocksAdditions/DTAlertView.m | 22 ++++++++++++----- .../DTProgressHUDDemo/Source/ViewController.m | 11 ++++----- 3 files changed, 39 insertions(+), 18 deletions(-) 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 :-(");