Skip to content

Instantly share code, notes, and snippets.

@alexfaber2011
Created June 8, 2015 19:19
Show Gist options
  • Save alexfaber2011/369daa6eadd79e2e9e7c to your computer and use it in GitHub Desktop.
Save alexfaber2011/369daa6eadd79e2e9e7c to your computer and use it in GitHub Desktop.
Form Value Grabbing
//Gather all of the form fields
NSMutableArray *smsValues = [[NSMutableArray alloc] initWithCapacity:3];
NSMutableArray *phoneValues = [[NSMutableArray alloc] initWithCapacity:3];
NSMutableArray *emailValues = [[NSMutableArray alloc] initWithCapacity:3];
NSArray *smsCells = [self.smsTable visibleCells];
NSArray *phoneCells = [self.phoneCallTable visibleCells];
NSArray *emailCells = [self.emailTable visibleCells];
for(NSUInteger i = 0; i < smsCells.count; i++){
//Does the compiler optimize this?
NSString *tempSmsText = ((MainCell *)smsCells[i]).textField.text;
NSString *tempPhoneText = ((MainCell *)phoneCells[i]).textField.text;
NSString *tempEmailText = ((MainCell *)emailCells[i]).textField.text;
if(![tempSmsText isEqualToString:@""])[smsValues addObject:tempSmsText];
if(![tempPhoneText isEqualToString:@""])[phoneValues addObject:tempPhoneText];
if(![tempEmailText isEqualToString:@""])[emailValues addObject:tempEmailText];
}
NSDictionary *newValues = @{
@"dnd" : @{
@"beginTime" : ((DNDCell *) [self.doNotDisturbTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]).fieldTextField.text,
@"endTime" : ((DNDCell *) [self.doNotDisturbTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]).fieldTextField.text
},
@"sms" : [[NSArray alloc] initWithArray:smsValues copyItems:YES],
@"phone" : [[NSArray alloc] initWithArray:phoneValues copyItems:YES],
@"email" : [[NSArray alloc] initWithArray:emailValues copyItems:YES]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment