I have a set of check boxes on my view controller, and they work great. Long story short: A user checks a box, and then taps the save button. Saving after checking a box posts the value 'yes' to a field in my database. However if no box is checked, and my user taps 'save', I'm thrown this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:]: count of objects (0) differs from count of keys (1)'
How can I stop the app from crashing if no box is checked, as checking a box is not mandatory? Code below (let me know if you need more - removed convoluted 'save' part of button action).
viewcontroller.m
- (IBAction)myCheck:(id)sender {
if (!checked17) {
[myCheck setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
checked17 = YES;
self.box = @"Yes";
}
else if (checked17) {
[myCheck setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
checked17 = NO;
self.box = @"No";
}
}
- (IBAction)submitButton:(id)sender {
NSDictionary *petOption = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:self.box, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *checkedFinish = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:petOption] forKey:@"und"];
[nodeData setObject:checkedFinish forKey:@"field_haveapet"];
}