From e6a4c8a4f6eb570f77412b016ac5f64e105da2e3 Mon Sep 17 00:00:00 2001 From: MSec Date: Thu, 10 Oct 2013 22:10:17 +1100 Subject: [PATCH] Added capability for additional text fields to be added to AlertViews Added code to be able to handle multiple textfields in an alertview simply by passing in placeholders for the desired textfields. Placeholders should be blank (@"") if no placeholder is required. An outlet has also been provided to be able to access the value in the textfields from the block for the Done button. There were a number of left over methods after these changes which I could not see a use for, so I have removed them to avoid clutter / unneccesary complexity --- .DS_Store | Bin 0 -> 6148 bytes .../BlockAlertsDemoViewController.m | 16 ++- .../BlockTextPromptAlertView.h | 11 +- .../BlockTextPromptAlertView.m | 117 ++++++++++-------- 4 files changed, 84 insertions(+), 60 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a093cea7df6cfa82d1dca0f1e00231afc416d6ab GIT binary patch literal 6148 zcmeHKJ5B>J5PbtFBGIIT&L=>kqckgXf?NP;7a>7bjv$dJD0~m@#EB?)<1vU8TTw&^ z%}Dke&(HRYVy^*6w;wKm6@Vq1qNp+>YMyl+wO~c5H6Cz<4Q}y>-AtjsXwtQxq2sDE zdVF916B2ha(teI-`Z5NNx7=IC{U+b7`#f%KORw+0t1{-4hW)Mw-d-;GYq&TA&VV!E z3^)S^V1ReF%JRg}duPBIa0b2@(DNa%DaMAyupS-k>Jxytpt%ZleM@LgXc!w7LwYD; zsYFYa_QViNr#-Z|*svH{I;76bI&J39$BWe2X%96V5)Hj~2AqK@1IIR8>HUArzs&3- zf12VWXTTZwXAH<9ty9NMwY&Al_Vlg|Y&UEw8dp@IP@jARaG>YNX?2=EsLr_9uo!9; Swbyi_e+X1UymJN)z`zG&*(x~z literal 0 HcmV?d00001 diff --git a/BlockAlertsDemo/BlockAlertsDemoViewController.m b/BlockAlertsDemo/BlockAlertsDemoViewController.m index f7fd47e..f67b7d0 100644 --- a/BlockAlertsDemo/BlockAlertsDemoViewController.m +++ b/BlockAlertsDemo/BlockAlertsDemoViewController.m @@ -72,7 +72,7 @@ - (IBAction)showActionSheetPlusAlert:(id)sender - (IBAction)goNuts:(id)sender { for (int i=0; i<6; i++) - { + { dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.5 * i * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ if (arc4random() % 2 == 0) @@ -80,13 +80,14 @@ - (IBAction)goNuts:(id)sender else [self showActionSheet:nil]; }); - } + } } - (IBAction)showTextPrompt:(id)sender { - UITextField *textField; - BlockTextPromptAlertView *alert = [BlockTextPromptAlertView promptWithTitle:@"Prompt Title" message:@"With prompts you do have to keep in mind limited screen space due to the keyboard" textField:&textField block:^(BlockTextPromptAlertView *alert){ + //The number of placeholders passed in defines how many textfields will be added to the alertview + NSArray* placeHolderArray = [[[NSArray alloc] initWithObjects:@"TextField 1",@"TextField 2", @"TextField 3", nil] autorelease]; + BlockTextPromptAlertView *alert = [BlockTextPromptAlertView promptWithTitle:@"Prompt Title" message:@"With prompts you do have to keep in mind limited screen space due to the keyboard" withPlaceholdersForTextFields:placeHolderArray block:^(BlockTextPromptAlertView *alert){ [alert.textField resignFirstResponder]; return YES; }]; @@ -94,7 +95,12 @@ - (IBAction)showTextPrompt:(id)sender [alert setCancelButtonWithTitle:@"Cancel" block:nil]; [alert addButtonWithTitle:@"Okay" block:^{ - NSLog(@"Text: %@", textField.text); + NSMutableArray *textField = [alert getArrayOfTextInAlertViewTextFields]; + int textfieldCount = [textField count]; + int i; + for (i=0; i 1) return NO; - else + else return YES; }