How do I enable validation if I only have a detail view which I create myself? I initialize as follows:
- (void)viewDidLoad {
[super viewDidLoad];
self.modalPresentationStyle = UIModalPresentationFormSheet;
self.title = @"Create New Account";
UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(submit)];
self.navigationItem.rightBarButtonItem = submitButton;
[submitButton release];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
self.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];
SCClassDefinition *dstRegClass = [SCClassDefinition definitionWithClass:[Registration class]
withPropertyNames:[NSArray arrayWithObjects:@"dstLogin", @"dstPassword", nil]
withPropertyTitles:[NSArray arrayWithObjects:@"DST Login", @"DST Password", nil]];
for (int i = 0; i < 2; i++) [dstRegClass propertyDefinitionAtIndex:i].autoValidate = NO;
SCClassDefinition *custRegClass = [SCClassDefinition definitionWithClass:[Registration class]
withPropertyNames:[NSArray arrayWithObjects:@"firstName", @"lastName", @"organization", @"email", @"username", nil]
withPropertyTitles:[NSArray arrayWithObjects:@"First Name", @"Last name", @"Organization", @"Email", @"Username", nil]];
for (int i = 0; i < 5; i++) [custRegClass propertyDefinitionAtIndex:i].autoValidate = NO;
self.model = [SCTableViewModel tableViewModelWithTableView:self.tableView withViewController:self];
self.record = [[[Registration alloc] init] autorelease];
SCObjectSection *dstSection = [SCObjectSection sectionWithHeaderTitle:@"DST Employees please provide your workstation credentials"
withBoundObject:self.record withClassDefinition:dstRegClass];
SCObjectSection *custSection = [SCObjectSection sectionWithHeaderTitle:@"DST Customers and Prospects please fill in all the fields below"
withBoundObject:self.record withClassDefinition:custRegClass];
custSection.footerTitle = @"When your account has been created you will receive an email containing details concerning Platypus access";
[self.model addSection:dstSection];
[self.model addSection:custSection];
}
and this validation method:
- (BOOL)tableViewModel:(SCTableViewModel *) tableViewModel valueIsValidForRowAtIndexPath:(NSIndexPath *) indexPath {
SCObjectSection *dstSection = (SCObjectSection *)[tableViewModel sectionAtIndex:0];
SCObjectSection *custSection = (SCObjectSection *)[tableViewModel sectionAtIndex:1];
SCTextFieldCell *dstName = (SCTextFieldCell *)[dstSection cellForPropertyName:@"dstLogin"];
SCTextFieldCell *dstPass = (SCTextFieldCell *)[dstSection cellForPropertyName:@"dstPassword"];
BOOL dstValid = [dstName.textField.text notEmpty] && [dstPass.textField.text notEmpty];
SCTextFieldCell *first = (SCTextFieldCell *)[custSection cellForPropertyName:@"firstName"];
SCTextFieldCell *last = (SCTextFieldCell *)[custSection cellForPropertyName:@"lastName"];
SCTextFieldCell *org = (SCTextFieldCell *)[custSection cellForPropertyName:@"organization"];
SCTextFieldCell *email = (SCTextFieldCell *)[custSection cellForPropertyName:@"email"];
SCTextFieldCell *user = (SCTextFieldCell *)[custSection cellForPropertyName:@"username"];
BOOL custValid = [first.textField.text notEmpty] && [last.textField.text notEmpty] &&
[org.textField.text notEmpty] && [email.textField.text notEmpty] &&
[user.textField.text notEmpty];
return dstValid ^ custValid;
}
which is checking to see whether all fields in only one of the two sections have a non-empty value.
A user has to either fill out the first section or the second section and in each section all fields are required.
In my .h file I have made my VC a SCTableViewModelDelegate
For some reason the done button is not being disabled/enabled at all.
I must be missing some critical wiring somewhere but I can't figure out what I forgot to do here...
How do I make this work?
Thanks,
Frank